[ Index ]

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


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1