[ Index ]

PHP Cross Reference of phpBB-3.3.3-deutsch

title

Body

[close]

/vendor/zendframework/zend-code/src/Scanner/ -> PropertyScanner.php (source)

   1  <?php
   2  /**
   3   * Zend Framework (http://framework.zend.com/)
   4   *
   5   * @link      http://github.com/zendframework/zf2 for the canonical source repository
   6   * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
   7   * @license   http://framework.zend.com/license/new-bsd New BSD License
   8   */
   9  
  10  namespace Zend\Code\Scanner;
  11  
  12  use Zend\Code\Annotation;
  13  use Zend\Code\Exception;
  14  use Zend\Code\NameInformation;
  15  
  16  use function is_array;
  17  use function is_numeric;
  18  use function is_string;
  19  use function ltrim;
  20  use function reset;
  21  use function strpos;
  22  use function substr;
  23  use function trim;
  24  use function var_export;
  25  
  26  class PropertyScanner implements ScannerInterface
  27  {
  28      const T_BOOLEAN = 'boolean';
  29      const T_INTEGER = 'int';
  30      const T_STRING  = 'string';
  31      const T_ARRAY   = 'array';
  32      const T_UNKNOWN = 'unknown';
  33  
  34      /**
  35       * @var bool
  36       */
  37      protected $isScanned = false;
  38  
  39      /**
  40       * @var array
  41       */
  42      protected $tokens;
  43  
  44      /**
  45       * @var NameInformation
  46       */
  47      protected $nameInformation;
  48  
  49      /**
  50       * @var string
  51       */
  52      protected $class;
  53  
  54      /**
  55       * @var ClassScanner
  56       */
  57      protected $scannerClass;
  58  
  59      /**
  60       * @var int
  61       */
  62      protected $lineStart;
  63  
  64      /**
  65       * @var bool
  66       */
  67      protected $isProtected = false;
  68  
  69      /**
  70       * @var bool
  71       */
  72      protected $isPublic = true;
  73  
  74      /**
  75       * @var bool
  76       */
  77      protected $isPrivate = false;
  78  
  79      /**
  80       * @var bool
  81       */
  82      protected $isStatic = false;
  83  
  84      /**
  85       * @var string
  86       */
  87      protected $docComment;
  88  
  89      /**
  90       * @var string
  91       */
  92      protected $name;
  93  
  94      /**
  95       * @var string
  96       */
  97      protected $value;
  98  
  99      /**
 100       * @var string
 101       */
 102      protected $valueType;
 103  
 104      /**
 105       * Constructor
 106       *
 107       * @param array $propertyTokens
 108       * @param NameInformation $nameInformation
 109       */
 110      public function __construct(array $propertyTokens, NameInformation $nameInformation = null)
 111      {
 112          $this->tokens = $propertyTokens;
 113          $this->nameInformation = $nameInformation;
 114      }
 115  
 116      /**
 117       * @param string $class
 118       */
 119      public function setClass($class)
 120      {
 121          $this->class = $class;
 122      }
 123  
 124      /**
 125       * @param ClassScanner $scannerClass
 126       */
 127      public function setScannerClass(ClassScanner $scannerClass)
 128      {
 129          $this->scannerClass = $scannerClass;
 130      }
 131  
 132      /**
 133       * @return ClassScanner
 134       */
 135      public function getClassScanner()
 136      {
 137          return $this->scannerClass;
 138      }
 139  
 140      /**
 141       * @return string
 142       */
 143      public function getName()
 144      {
 145          $this->scan();
 146          return $this->name;
 147      }
 148  
 149      /**
 150       * @return string
 151       */
 152      public function getValueType()
 153      {
 154          $this->scan();
 155          return $this->valueType;
 156      }
 157  
 158      /**
 159       * @return bool
 160       */
 161      public function isPublic()
 162      {
 163          $this->scan();
 164          return $this->isPublic;
 165      }
 166  
 167      /**
 168       * @return bool
 169       */
 170      public function isPrivate()
 171      {
 172          $this->scan();
 173          return $this->isPrivate;
 174      }
 175  
 176      /**
 177       * @return bool
 178       */
 179      public function isProtected()
 180      {
 181          $this->scan();
 182          return $this->isProtected;
 183      }
 184  
 185      /**
 186       * @return bool
 187       */
 188      public function isStatic()
 189      {
 190          $this->scan();
 191          return $this->isStatic;
 192      }
 193  
 194      /**
 195       * @return string
 196       */
 197      public function getValue()
 198      {
 199          $this->scan();
 200          return $this->value;
 201      }
 202  
 203      /**
 204       * @return string
 205       */
 206      public function getDocComment()
 207      {
 208          $this->scan();
 209          return $this->docComment;
 210      }
 211  
 212      /**
 213       * @param Annotation\AnnotationManager $annotationManager
 214       * @return AnnotationScanner|false
 215       */
 216      public function getAnnotations(Annotation\AnnotationManager $annotationManager)
 217      {
 218          if (($docComment = $this->getDocComment()) == '') {
 219              return false;
 220          }
 221  
 222          return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation);
 223      }
 224  
 225      /**
 226       * @return string
 227       */
 228      public function __toString()
 229      {
 230          $this->scan();
 231          return var_export($this, true);
 232      }
 233  
 234      /**
 235       * Scan tokens
 236       *
 237       * @throws \Zend\Code\Exception\RuntimeException
 238       */
 239      protected function scan()
 240      {
 241          if ($this->isScanned) {
 242              return;
 243          }
 244  
 245          if (! $this->tokens) {
 246              throw new Exception\RuntimeException('No tokens were provided');
 247          }
 248  
 249          /**
 250           * Variables & Setup
 251           */
 252          $value            = '';
 253          $concatenateValue = false;
 254  
 255          $tokens = &$this->tokens;
 256          reset($tokens);
 257  
 258          foreach ($tokens as $token) {
 259              $tempValue = $token;
 260              if (! is_string($token)) {
 261                  list($tokenType, $tokenContent, $tokenLine) = $token;
 262  
 263                  switch ($tokenType) {
 264                      case T_DOC_COMMENT:
 265                          if ($this->docComment === null && $this->name === null) {
 266                              $this->docComment = $tokenContent;
 267                          }
 268                          break;
 269  
 270                      case T_VARIABLE:
 271                          $this->name = ltrim($tokenContent, '$');
 272                          break;
 273  
 274                      case T_PUBLIC:
 275                          // use defaults
 276                          break;
 277  
 278                      case T_PROTECTED:
 279                          $this->isProtected = true;
 280                          $this->isPublic = false;
 281                          break;
 282  
 283                      case T_PRIVATE:
 284                          $this->isPrivate = true;
 285                          $this->isPublic = false;
 286                          break;
 287  
 288                      case T_STATIC:
 289                          $this->isStatic = true;
 290                          break;
 291                      default:
 292                          $tempValue = trim($tokenContent);
 293                          break;
 294                  }
 295              }
 296  
 297              //end value concatenation
 298              if (! is_array($token) && trim($token) == ';') {
 299                  $concatenateValue = false;
 300              }
 301  
 302              if (true === $concatenateValue) {
 303                  $value .= $tempValue;
 304              }
 305  
 306              //start value concatenation
 307              if (! is_array($token) && trim($token) == '=') {
 308                  $concatenateValue = true;
 309              }
 310          }
 311  
 312          $this->valueType = self::T_UNKNOWN;
 313          if ($value == 'false' || $value == 'true') {
 314              $this->valueType = self::T_BOOLEAN;
 315          } elseif (is_numeric($value)) {
 316              $this->valueType = self::T_INTEGER;
 317          } elseif (0 === strpos($value, 'array') || 0 === strpos($value, '[')) {
 318              $this->valueType = self::T_ARRAY;
 319          } elseif (0 === strpos($value, '"') || 0 === strpos($value, "'")) {
 320              $value = substr($value, 1, -1); // Remove quotes
 321              $this->valueType = self::T_STRING;
 322          }
 323  
 324          $this->value = empty($value) ? null : $value;
 325          $this->isScanned = true;
 326      }
 327  }


Generated: Sun Feb 14 20:08:31 2021 Cross-referenced by PHPXref 0.7.1