Source of file PropertyScanner.php
Size: 6,786 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Code/Scanner/PropertyScanner.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 | <?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 PropertyScanner implements ScannerInterface { const T_BOOLEAN = "boolean"; const T_INTEGER = "int"; const T_STRING = "string"; const T_ARRAY = "array"; const T_UNKNOWN = "unknown"; /** * @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 bool */ protected $isProtected = false; /** * @var bool */ protected $isPublic = true; /** * @var bool */ protected $isPrivate = false; /** * @var bool */ protected $isStatic = false; /** * @var string */ protected $docComment; /** * @var string */ protected $name; /** * @var string */ protected $value; /** * @var string */ protected $valueType; /** * Constructor * * @param array $propertyTokens * @param NameInformation $nameInformation */ public function __construct(array $propertyTokens, NameInformation $nameInformation = null) { $this->tokens = $propertyTokens; $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 getValueType() { return $this->valueType; } /** * @return bool */ public function isPublic() { $this->scan(); return $this->isPublic; } /** * @return bool */ public function isPrivate() { $this->scan(); return $this->isPrivate; } /** * @return bool */ public function isProtected() { $this->scan(); return $this->isProtected; } /** * @return bool */ public function isStatic() { $this->scan(); return $this->isStatic; } /** * @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 \Zend\Code\Exception\RuntimeException */ protected function scan() { if ($this->isScanned) { return; } if (!$this->tokens) { throw new Exception\RuntimeException('No tokens were provided'); } /** * Variables & Setup */ $value = ''; $concatenateValue = false; $tokens = &$this->tokens; reset($tokens); foreach($tokens as $token) { $tempValue = $token; 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; } break; case T_VARIABLE: $this->name = ltrim($tokenContent, '$'); break; case T_PUBLIC: // use defaults break; case T_PROTECTED: $this->isProtected = true; $this->isPublic = false; break; case T_PRIVATE: $this->isPrivate = true; $this->isPublic = false; break; case T_STATIC: $this->isStatic = true; break; default: $tempValue = trim($tokenContent); break; } } //end value concatenation if(!is_array($token) && trim($token) == ";") { $concatenateValue = false; } if(true === $concatenateValue) { $value .= $tempValue; } //start value concatenation if(!is_array($token) && trim($token) == "=") { $concatenateValue = true; } } $this->valueType = self::T_UNKNOWN; if($value == "false" || $value == "true") { $this->valueType = self::T_BOOLEAN; } elseif(is_numeric($value)) { $this->valueType = self::T_INTEGER; } elseif(0 === strpos($value, 'array') || 0 === strpos($value, "[")) { $this->valueType = self::T_ARRAY; } elseif (substr($value, 0, 1) === '"' || substr($value, 0, 1) === "'") { $value = substr($value, 1, -1); // Remove quotes $this->valueType = self::T_STRING; } $this->value = empty($value) ? null : $value; $this->isScanned = true; } } |