[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/zendframework/zend-code/src/Scanner/ -> ParameterScanner.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\NameInformation;
  13  
  14  use function current;
  15  use function is_string;
  16  use function ltrim;
  17  use function next;
  18  use function reset;
  19  use function trim;
  20  
  21  class ParameterScanner
  22  {
  23      /**
  24       * @var bool
  25       */
  26      protected $isScanned = false;
  27  
  28      /**
  29       * @var null|ClassScanner
  30       */
  31      protected $declaringScannerClass;
  32  
  33      /**
  34       * @var null|string
  35       */
  36      protected $declaringClass;
  37  
  38      /**
  39       * @var null|MethodScanner
  40       */
  41      protected $declaringScannerFunction;
  42  
  43      /**
  44       * @var null|string
  45       */
  46      protected $declaringFunction;
  47  
  48      /**
  49       * @var null|string
  50       */
  51      protected $defaultValue;
  52  
  53      /**
  54       * @var null|string
  55       */
  56      protected $class;
  57  
  58      /**
  59       * @var null|string
  60       */
  61      protected $name;
  62  
  63      /**
  64       * @var null|int
  65       */
  66      protected $position;
  67  
  68      /**
  69       * @var bool
  70       */
  71      protected $isArray = false;
  72  
  73      /**
  74       * @var bool
  75       */
  76      protected $isDefaultValueAvailable = false;
  77  
  78      /**
  79       * @var bool
  80       */
  81      protected $isOptional = false;
  82  
  83      /**
  84       * @var bool
  85       */
  86      protected $isPassedByReference = false;
  87  
  88      /**
  89       * @var array|null
  90       */
  91      protected $tokens;
  92  
  93      /**
  94       * @var null|NameInformation
  95       */
  96      protected $nameInformation;
  97  
  98      /**
  99       * @param  array $parameterTokens
 100       * @param  NameInformation $nameInformation
 101       */
 102      public function __construct(array $parameterTokens, NameInformation $nameInformation = null)
 103      {
 104          $this->tokens          = $parameterTokens;
 105          $this->nameInformation = $nameInformation;
 106      }
 107  
 108      /**
 109       * Set declaring class
 110       *
 111       * @param  string $class
 112       * @return void
 113       */
 114      public function setDeclaringClass($class)
 115      {
 116          $this->declaringClass = (string) $class;
 117      }
 118  
 119      /**
 120       * Set declaring scanner class
 121       *
 122       * @param  ClassScanner $scannerClass
 123       * @return void
 124       */
 125      public function setDeclaringScannerClass(ClassScanner $scannerClass)
 126      {
 127          $this->declaringScannerClass = $scannerClass;
 128      }
 129  
 130      /**
 131       * Set declaring function
 132       *
 133       * @param  string $function
 134       * @return void
 135       */
 136      public function setDeclaringFunction($function)
 137      {
 138          $this->declaringFunction = $function;
 139      }
 140  
 141      /**
 142       * Set declaring scanner function
 143       *
 144       * @param  MethodScanner $scannerFunction
 145       * @return void
 146       */
 147      public function setDeclaringScannerFunction(MethodScanner $scannerFunction)
 148      {
 149          $this->declaringScannerFunction = $scannerFunction;
 150      }
 151  
 152      /**
 153       * Set position
 154       *
 155       * @param  int $position
 156       * @return void
 157       */
 158      public function setPosition($position)
 159      {
 160          $this->position = $position;
 161      }
 162  
 163      /**
 164       * Scan
 165       *
 166       * @return void
 167       */
 168      protected function scan()
 169      {
 170          if ($this->isScanned) {
 171              return;
 172          }
 173  
 174          $tokens = &$this->tokens;
 175  
 176          reset($tokens);
 177  
 178          SCANNER_TOP:
 179  
 180          $token = current($tokens);
 181  
 182          if (is_string($token)) {
 183              // check pass by ref
 184              if ($token === '&') {
 185                  $this->isPassedByReference = true;
 186                  goto SCANNER_CONTINUE;
 187              }
 188              if ($token === '=') {
 189                  $this->isOptional              = true;
 190                  $this->isDefaultValueAvailable = true;
 191                  goto SCANNER_CONTINUE;
 192              }
 193          } else {
 194              if ($this->name === null && ($token[0] === T_STRING || $token[0] === T_NS_SEPARATOR)) {
 195                  $this->class .= $token[1];
 196                  goto SCANNER_CONTINUE;
 197              }
 198              if ($token[0] === T_VARIABLE) {
 199                  $this->name = ltrim($token[1], '$');
 200                  goto SCANNER_CONTINUE;
 201              }
 202          }
 203  
 204          if ($this->name !== null) {
 205              $this->defaultValue .= trim(is_string($token) ? $token : $token[1]);
 206          }
 207  
 208          SCANNER_CONTINUE:
 209  
 210          if (next($this->tokens) === false) {
 211              goto SCANNER_END;
 212          }
 213          goto SCANNER_TOP;
 214  
 215          SCANNER_END:
 216  
 217          if ($this->class && $this->nameInformation) {
 218              $this->class = $this->nameInformation->resolveName($this->class);
 219          }
 220  
 221          $this->isScanned = true;
 222      }
 223  
 224      /**
 225       * Get declaring scanner class
 226       *
 227       * @return ClassScanner
 228       */
 229      public function getDeclaringScannerClass()
 230      {
 231          return $this->declaringScannerClass;
 232      }
 233  
 234      /**
 235       * Get declaring class
 236       *
 237       * @return string
 238       */
 239      public function getDeclaringClass()
 240      {
 241          return $this->declaringClass;
 242      }
 243  
 244      /**
 245       * Get declaring scanner function
 246       *
 247       * @return MethodScanner
 248       */
 249      public function getDeclaringScannerFunction()
 250      {
 251          return $this->declaringScannerFunction;
 252      }
 253  
 254      /**
 255       * Get declaring function
 256       *
 257       * @return string
 258       */
 259      public function getDeclaringFunction()
 260      {
 261          return $this->declaringFunction;
 262      }
 263  
 264      /**
 265       * Get default value
 266       *
 267       * @return string
 268       */
 269      public function getDefaultValue()
 270      {
 271          $this->scan();
 272  
 273          return $this->defaultValue;
 274      }
 275  
 276      /**
 277       * Get class
 278       *
 279       * @return string
 280       */
 281      public function getClass()
 282      {
 283          $this->scan();
 284  
 285          return $this->class;
 286      }
 287  
 288      /**
 289       * Get name
 290       *
 291       * @return string
 292       */
 293      public function getName()
 294      {
 295          $this->scan();
 296  
 297          return $this->name;
 298      }
 299  
 300      /**
 301       * Get position
 302       *
 303       * @return int
 304       */
 305      public function getPosition()
 306      {
 307          $this->scan();
 308  
 309          return $this->position;
 310      }
 311  
 312      /**
 313       * Check if is array
 314       *
 315       * @return bool
 316       */
 317      public function isArray()
 318      {
 319          $this->scan();
 320  
 321          return $this->isArray;
 322      }
 323  
 324      /**
 325       * Check if default value is available
 326       *
 327       * @return bool
 328       */
 329      public function isDefaultValueAvailable()
 330      {
 331          $this->scan();
 332  
 333          return $this->isDefaultValueAvailable;
 334      }
 335  
 336      /**
 337       * Check if is optional
 338       *
 339       * @return bool
 340       */
 341      public function isOptional()
 342      {
 343          $this->scan();
 344  
 345          return $this->isOptional;
 346      }
 347  
 348      /**
 349       * Check if is passed by reference
 350       *
 351       * @return bool
 352       */
 353      public function isPassedByReference()
 354      {
 355          $this->scan();
 356  
 357          return $this->isPassedByReference;
 358      }
 359  }


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1