3 * Zend Framework (http://framework.zend.com/)
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
10 namespace Zend\Code\Scanner
;
12 use Zend\Code\Annotation
;
13 use Zend\Code\Exception
;
14 use Zend\Code\NameInformation
;
16 class ConstantScanner
implements ScannerInterface
21 protected $isScanned = false;
29 * @var NameInformation
31 protected $nameInformation;
41 protected $scannerClass;
51 protected $docComment;
66 * @param array $constantTokens
67 * @param NameInformation $nameInformation
69 public function __construct(array $constantTokens, NameInformation
$nameInformation = null)
71 $this->tokens
= $constantTokens;
72 $this->nameInformation
= $nameInformation;
76 * @param string $class
78 public function setClass($class)
80 $this->class = $class;
84 * @param ClassScanner $scannerClass
86 public function setScannerClass(ClassScanner
$scannerClass)
88 $this->scannerClass
= $scannerClass;
92 * @return ClassScanner
94 public function getClassScanner()
96 return $this->scannerClass
;
102 public function getName()
111 public function getValue()
120 public function getDocComment()
123 return $this->docComment
;
127 * @param Annotation\AnnotationManager $annotationManager
128 * @return AnnotationScanner
130 public function getAnnotations(Annotation\AnnotationManager
$annotationManager)
132 if (($docComment = $this->getDocComment()) == '') {
136 return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation
);
142 public function __toString()
145 return var_export($this, true);
151 * @throws Exception\RuntimeException
153 protected function scan()
155 if ($this->isScanned
) {
159 if (!$this->tokens
) {
160 throw new Exception\
RuntimeException('No tokens were provided');
166 $tokens = &$this->tokens
;
172 $token = current($tokens);
174 if (!is_string($token)) {
175 list($tokenType, $tokenContent, $tokenLine) = $token;
177 switch ($tokenType) {
179 if ($this->docComment
=== null && $this->name
=== null) {
180 $this->docComment
= $tokenContent;
182 goto SCANNER_CONTINUE
;
186 $string = (is_string($token)) ?
$token : $tokenContent;
188 if (null === $this->name
) {
189 $this->name
= $string;
191 if ('self' == strtolower($string)) {
192 list($tokenNextType, $tokenNextContent, $tokenNextLine) = next($tokens);
194 if ('::' == $tokenNextContent) {
195 list($tokenNextType, $tokenNextContent, $tokenNextLine) = next($tokens);
197 if ($this->getClassScanner()->getConstant($tokenNextContent)) {
198 $this->value
= $this->getClassScanner()->getConstant($tokenNextContent)->getValue();
204 goto SCANNER_CONTINUE
;
207 case T_CONSTANT_ENCAPSED_STRING
:
210 $string = (is_string($token)) ?
$token : $tokenContent;
212 if (substr($string, 0, 1) === '"' ||
substr($string, 0, 1) === "'") {
213 $this->value
= substr($string, 1, -1); // Remove quotes
215 $this->value
= $string;
217 goto SCANNER_CONTINUE
;
221 goto SCANNER_CONTINUE
;
227 if (next($this->tokens
) === false) {
234 $this->isScanned
= true;