Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Code / Scanner / ConstantScanner.php
blob02617c710bc1c912bb230462da150867ff47e436
1 <?php
2 /**
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
8 */
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
18 /**
19 * @var bool
21 protected $isScanned = false;
23 /**
24 * @var array
26 protected $tokens;
28 /**
29 * @var NameInformation
31 protected $nameInformation;
33 /**
34 * @var string
36 protected $class;
38 /**
39 * @var ClassScanner
41 protected $scannerClass;
43 /**
44 * @var int
46 protected $lineStart;
48 /**
49 * @var string
51 protected $docComment;
53 /**
54 * @var string
56 protected $name;
58 /**
59 * @var string
61 protected $value;
63 /**
64 * Constructor
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;
75 /**
76 * @param string $class
78 public function setClass($class)
80 $this->class = $class;
83 /**
84 * @param ClassScanner $scannerClass
86 public function setScannerClass(ClassScanner $scannerClass)
88 $this->scannerClass = $scannerClass;
91 /**
92 * @return ClassScanner
94 public function getClassScanner()
96 return $this->scannerClass;
99 /**
100 * @return string
102 public function getName()
104 $this->scan();
105 return $this->name;
109 * @return string
111 public function getValue()
113 $this->scan();
114 return $this->value;
118 * @return string
120 public function getDocComment()
122 $this->scan();
123 return $this->docComment;
127 * @param Annotation\AnnotationManager $annotationManager
128 * @return AnnotationScanner
130 public function getAnnotations(Annotation\AnnotationManager $annotationManager)
132 if (($docComment = $this->getDocComment()) == '') {
133 return false;
136 return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation);
140 * @return string
142 public function __toString()
144 $this->scan();
145 return var_export($this, true);
149 * Scan tokens
151 * @throws Exception\RuntimeException
153 protected function scan()
155 if ($this->isScanned) {
156 return;
159 if (!$this->tokens) {
160 throw new Exception\RuntimeException('No tokens were provided');
164 * Variables & Setup
166 $tokens = &$this->tokens;
168 reset($tokens);
170 SCANNER_TOP:
172 $token = current($tokens);
174 if (!is_string($token)) {
175 list($tokenType, $tokenContent, $tokenLine) = $token;
177 switch ($tokenType) {
178 case T_DOC_COMMENT:
179 if ($this->docComment === null && $this->name === null) {
180 $this->docComment = $tokenContent;
182 goto SCANNER_CONTINUE;
184 case T_STRING:
185 $string = (is_string($token)) ? $token : $tokenContent;
187 if (null === $this->name) {
188 $this->name = $string;
189 } else {
190 if ('self' == strtolower($string)) {
191 list($tokenNextType, $tokenNextContent, $tokenNextLine) = next($tokens);
193 if ('::' == $tokenNextContent) {
194 list($tokenNextType, $tokenNextContent, $tokenNextLine) = next($tokens);
196 if ($this->getClassScanner()->getConstant($tokenNextContent)) {
197 $this->value = $this->getClassScanner()->getConstant($tokenNextContent)->getValue();
203 goto SCANNER_CONTINUE;
205 case T_CONSTANT_ENCAPSED_STRING:
206 case T_DNUMBER:
207 case T_LNUMBER:
208 $string = (is_string($token)) ? $token : $tokenContent;
210 if (substr($string, 0, 1) === '"' || substr($string, 0, 1) === "'") {
211 $this->value = substr($string, 1, -1); // Remove quotes
212 } else {
213 $this->value = $string;
215 goto SCANNER_CONTINUE;
217 default:
218 goto SCANNER_CONTINUE;
222 SCANNER_CONTINUE:
224 if (next($this->tokens) === false) {
225 goto SCANNER_END;
227 goto SCANNER_TOP;
229 SCANNER_END:
231 $this->isScanned = true;