Source of file ConstantScanner.php
Size: 5,342 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Code/Scanner/ConstantScanner.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 | <?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\Annotation; use Zend\Code\Exception; use Zend\Code\NameInformation; class ConstantScanner implements ScannerInterface { /** * @var bool */ protected $isScanned = false; /** * @var array */ protected $tokens; /** * @var NameInformation */ protected $nameInformation; /** * @var string */ protected $class; /** * @var ClassScanner */ protected $scannerClass; /** * @var int */ protected $lineStart; /** * @var string */ protected $docComment; /** * @var string */ protected $name; /** * @var string */ protected $value; /** * Constructor * * @param array $constantTokens * @param NameInformation $nameInformation */ public function __construct(array $constantTokens, NameInformation $nameInformation = null) { $this->tokens = $constantTokens; $this->nameInformation = $nameInformation; } /** * @param string $class */ public function setClass($class) { $this->class = $class; } /** * @param ClassScanner $scannerClass */ public function setScannerClass(ClassScanner $scannerClass) { $this->scannerClass = $scannerClass; } /** * @return ClassScanner */ public function getClassScanner() { return $this->scannerClass; } /** * @return string */ public function getName() { $this->scan(); return $this->name; } /** * @return string */ public function getValue() { $this->scan(); return $this->value; } /** * @return string */ public function getDocComment() { $this->scan(); return $this->docComment; } /** * @param Annotation\AnnotationManager $annotationManager * @return AnnotationScanner */ public function getAnnotations(Annotation\AnnotationManager $annotationManager) { if (($docComment = $this->getDocComment()) == '') { return false; } return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation); } /** * @return string */ public function __toString() { $this->scan(); return var_export($this, true); } /** * Scan tokens * * @throws Exception\RuntimeException */ protected function scan() { if ($this->isScanned) { return; } if (!$this->tokens) { throw new Exception\RuntimeException('No tokens were provided'); } /** * Variables & Setup */ $tokens = &$this->tokens; reset($tokens); SCANNER_TOP: $token = current($tokens); if (!is_string($token)) { list($tokenType, $tokenContent, $tokenLine) = $token; switch ($tokenType) { case T_DOC_COMMENT: if ($this->docComment === null && $this->name === null) { $this->docComment = $tokenContent; } goto SCANNER_CONTINUE; case T_STRING: $string = (is_string($token)) ? $token : $tokenContent; if (null === $this->name) { $this->name = $string; } else { if ('self' == strtolower($string)) { list($tokenNextType, $tokenNextContent, $tokenNextLine) = next($tokens); if ('::' == $tokenNextContent) { list($tokenNextType, $tokenNextContent, $tokenNextLine) = next($tokens); if ($this->getClassScanner()->getConstant($tokenNextContent)) { $this->value = $this->getClassScanner()->getConstant($tokenNextContent)->getValue(); } } } } goto SCANNER_CONTINUE; case T_CONSTANT_ENCAPSED_STRING: case T_DNUMBER: case T_LNUMBER: $string = (is_string($token)) ? $token : $tokenContent; if (substr($string, 0, 1) === '"' || substr($string, 0, 1) === "'") { $this->value = substr($string, 1, -1); // Remove quotes } else { $this->value = $string; } goto SCANNER_CONTINUE; default: goto SCANNER_CONTINUE; } } SCANNER_CONTINUE: if (next($this->tokens) === false) { goto SCANNER_END; } goto SCANNER_TOP; SCANNER_END: $this->isScanned = true; } } |