3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 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 PropertyScanner
implements ScannerInterface
21 protected $isScanned = false;
29 * @var NameInformation
31 protected $nameInformation;
41 protected $scannerClass;
51 protected $isProtected = false;
56 protected $isPublic = true;
61 protected $isPrivate = false;
66 protected $isStatic = false;
71 protected $docComment;
86 * @param array $propertyTokens
87 * @param NameInformation $nameInformation
89 public function __construct(array $propertyTokens, NameInformation
$nameInformation = null)
91 $this->tokens
= $propertyTokens;
92 $this->nameInformation
= $nameInformation;
96 * @param string $class
98 public function setClass($class)
100 $this->class = $class;
104 * @param ClassScanner $scannerClass
106 public function setScannerClass(ClassScanner
$scannerClass)
108 $this->scannerClass
= $scannerClass;
112 * @return ClassScanner
114 public function getClassScanner()
116 return $this->scannerClass
;
122 public function getName()
131 public function isPublic()
134 return $this->isPublic
;
140 public function isPrivate()
143 return $this->isPrivate
;
149 public function isProtected()
152 return $this->isProtected
;
158 public function isStatic()
161 return $this->isStatic
;
167 public function getValue()
176 public function getDocComment()
179 return $this->docComment
;
183 * @param Annotation\AnnotationManager $annotationManager
184 * @return AnnotationScanner
186 public function getAnnotations(Annotation\AnnotationManager
$annotationManager)
188 if (($docComment = $this->getDocComment()) == '') {
192 return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation
);
198 public function __toString()
201 return var_export($this, true);
207 * @throws \Zend\Code\Exception\RuntimeException
209 protected function scan()
211 if ($this->isScanned
) {
215 if (!$this->tokens
) {
216 throw new Exception\
RuntimeException('No tokens were provided');
222 $tokens = &$this->tokens
;
228 $token = current($tokens);
230 if (!is_string($token)) {
231 list($tokenType, $tokenContent, $tokenLine) = $token;
233 switch ($tokenType) {
235 if ($this->docComment
=== null && $this->name
=== null) {
236 $this->docComment
= $tokenContent;
238 goto SCANNER_CONTINUE
;
241 $this->name
= ltrim($tokenContent, '$');
242 goto SCANNER_CONTINUE
;
246 goto SCANNER_CONTINUE
;
249 $this->isProtected
= true;
250 $this->isPublic
= false;
251 goto SCANNER_CONTINUE
;
254 $this->isPrivate
= true;
255 $this->isPublic
= false;
256 goto SCANNER_CONTINUE
;
259 $this->isStatic
= true;
260 goto SCANNER_CONTINUE
;
263 if ($this->name
!== null && trim($tokenContent) !== '') {
264 $this->value
.= (is_string($token)) ?
$token : $tokenContent;
265 if (substr($this->value
, 0, 1) === '"' ||
substr($this->value
, 0, 1) === "'") {
266 $this->value
= substr($this->value
, 1, -1); // Remove quotes
269 goto SCANNER_CONTINUE
;
275 if (next($this->tokens
) === false) {
282 $this->isScanned
= true;