Source of file ParameterScanner.php
Size: 6,688 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Code/Scanner/ParameterScanner.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Code\Scanner; use Zend\Code\NameInformation; class ParameterScanner { /** * @var bool */ protected $isScanned = false; /** * @var null|ClassScanner */ protected $declaringScannerClass = null; /** * @var null|string */ protected $declaringClass = null; /** * @var null|MethodScanner */ protected $declaringScannerFunction = null; /** * @var null|string */ protected $declaringFunction = null; /** * @var null|string */ protected $defaultValue = null; /** * @var null|string */ protected $class = null; /** * @var null|string */ protected $name = null; /** * @var null|int */ protected $position = null; /** * @var bool */ protected $isArray = false; /** * @var bool */ protected $isDefaultValueAvailable = false; /** * @var bool */ protected $isOptional = false; /** * @var bool */ protected $isPassedByReference = false; /** * @var array|null */ protected $tokens = null; /** * @var null|NameInformation */ protected $nameInformation = null; /** * @param array $parameterTokens * @param NameInformation $nameInformation */ public function __construct(array $parameterTokens, NameInformation $nameInformation = null) { $this->tokens = $parameterTokens; $this->nameInformation = $nameInformation; } /** * Set declaring class * * @param string $class * @return void */ public function setDeclaringClass($class) { $this->declaringClass = (string) $class; } /** * Set declaring scanner class * * @param ClassScanner $scannerClass * @return void */ public function setDeclaringScannerClass(ClassScanner $scannerClass) { $this->declaringScannerClass = $scannerClass; } /** * Set declaring function * * @param string $function * @return void */ public function setDeclaringFunction($function) { $this->declaringFunction = $function; } /** * Set declaring scanner function * * @param MethodScanner $scannerFunction * @return void */ public function setDeclaringScannerFunction(MethodScanner $scannerFunction) { $this->declaringScannerFunction = $scannerFunction; } /** * Set position * * @param int $position * @return void */ public function setPosition($position) { $this->position = $position; } /** * Scan * * @return void */ protected function scan() { if ($this->isScanned) { return; } $tokens = &$this->tokens; reset($tokens); SCANNER_TOP: $token = current($tokens); if (is_string($token)) { // check pass by ref if ($token === '&') { $this->isPassedByReference = true; goto SCANNER_CONTINUE; } if ($token === '=') { $this->isOptional = true; $this->isDefaultValueAvailable = true; goto SCANNER_CONTINUE; } } else { if ($this->name === null && ($token[0] === T_STRING || $token[0] === T_NS_SEPARATOR)) { $this->class .= $token[1]; goto SCANNER_CONTINUE; } if ($token[0] === T_VARIABLE) { $this->name = ltrim($token[1], '$'); goto SCANNER_CONTINUE; } } if ($this->name !== null) { $this->defaultValue .= trim((is_string($token)) ? $token : $token[1]); } SCANNER_CONTINUE: if (next($this->tokens) === false) { goto SCANNER_END; } goto SCANNER_TOP; SCANNER_END: if ($this->class && $this->nameInformation) { $this->class = $this->nameInformation->resolveName($this->class); } $this->isScanned = true; } /** * Get declaring scanner class * * @return ClassScanner */ public function getDeclaringScannerClass() { return $this->declaringScannerClass; } /** * Get declaring class * * @return string */ public function getDeclaringClass() { return $this->declaringClass; } /** * Get declaring scanner function * * @return MethodScanner */ public function getDeclaringScannerFunction() { return $this->declaringScannerFunction; } /** * Get declaring function * * @return string */ public function getDeclaringFunction() { return $this->declaringFunction; } /** * Get default value * * @return string */ public function getDefaultValue() { $this->scan(); return $this->defaultValue; } /** * Get class * * @return string */ public function getClass() { $this->scan(); return $this->class; } /** * Get name * * @return string */ public function getName() { $this->scan(); return $this->name; } /** * Get position * * @return int */ public function getPosition() { $this->scan(); return $this->position; } /** * Check if is array * * @return bool */ public function isArray() { $this->scan(); return $this->isArray; } /** * Check if default value is available * * @return bool */ public function isDefaultValueAvailable() { $this->scan(); return $this->isDefaultValueAvailable; } /** * Check if is optional * * @return bool */ public function isOptional() { $this->scan(); return $this->isOptional; } /** * Check if is passed by reference * * @return bool */ public function isPassedByReference() { $this->scan(); return $this->isPassedByReference; } } |