1: <?php
2: /**
3: * PHP Token Reflection
4: *
5: * Version 1.3.1
6: *
7: * LICENSE
8: *
9: * This source file is subject to the new BSD license that is bundled
10: * with this library in the file LICENSE.
11: *
12: * @author Ondřej Nešpor
13: * @author Jaroslav Hanslík
14: */
15:
16: namespace TokenReflection\Invalid;
17:
18: use TokenReflection, TokenReflection\IReflectionConstant, TokenReflection\Broker, TokenReflection\ReflectionBase;
19:
20: /**
21: * Invalid constant reflection.
22: *
23: * The reflected constant is not unique.
24: */
25: class ReflectionConstant extends ReflectionElement implements IReflectionConstant
26: {
27: /**
28: * Constant name.
29: *
30: * @var string
31: */
32: private $name;
33:
34: /**
35: * Original definition file name.
36: *
37: * @var string
38: */
39: private $fileName;
40:
41: /**
42: * Reflection broker.
43: *
44: * @var \TokenReflection\Broker
45: */
46: private $broker;
47:
48: /**
49: * Constructor.
50: *
51: * @param string $name Constant name
52: * @param string $fileName Original definiton file name
53: * @param \TokenReflection\Broker $broker Reflection broker
54: */
55: public function __construct($name, $fileName, Broker $broker)
56: {
57: $this->name = $name;
58: $this->broker = $broker;
59: $this->fileName = $fileName;
60: }
61:
62: /**
63: * Returns the name.
64: *
65: * @return string
66: */
67: public function getName()
68: {
69: return $this->name;
70: }
71:
72: /**
73: * Returns the unqualified name (UQN).
74: *
75: * @return string
76: */
77: public function getShortName()
78: {
79: $pos = strrpos($this->name, '\\');
80: return false === $pos ? $this->name : substr($this->name, $pos + 1);
81: }
82:
83: /**
84: * Returns the declaring class reflection.
85: *
86: * @return null
87: */
88: public function getDeclaringClass()
89: {
90: return null;
91: }
92:
93: /**
94: * Returns the declaring class name.
95: *
96: * @return null
97: */
98: public function getDeclaringClassName()
99: {
100: return null;
101: }
102:
103: /**
104: * Returns the namespace name.
105: *
106: * @return string
107: */
108: public function getNamespaceName()
109: {
110: $pos = strrpos($this->name, '\\');
111: return false === $pos ? '' : substr($this->name, 0, $pos);
112: }
113:
114: /**
115: * Returns if the function/method is defined within a namespace.
116: *
117: * @return boolean
118: */
119: public function inNamespace()
120: {
121: return false !== strpos($this->name, '\\');
122: }
123:
124: /**
125: * Returns the PHP extension reflection.
126: *
127: * @return null
128: */
129: public function getExtension()
130: {
131: return null;
132: }
133:
134: /**
135: * Returns the PHP extension name.
136: *
137: * @return boolean
138: */
139: public function getExtensionName()
140: {
141: return false;
142: }
143:
144: /**
145: * Returns the appropriate source code part.
146: *
147: * @return string
148: */
149: public function getSource()
150: {
151: return '';
152: }
153:
154: /**
155: * Returns the start position in the file token stream.
156: *
157: * @return integer
158: */
159: public function getStartPosition()
160: {
161: return -1;
162: }
163:
164: /**
165: * Returns the end position in the file token stream.
166: *
167: * @return integer
168: */
169: public function getEndPosition()
170: {
171: return -1;
172: }
173:
174: /**
175: * Returns the file name the reflection object is defined in.
176: *
177: * @return null
178: */
179: public function getFileName()
180: {
181: return $this->fileName;
182: }
183:
184: /**
185: * Returns a file reflection.
186: *
187: * @return \TokenReflection\ReflectionFile
188: * @throws \TokenReflection\Exception\RuntimeException If the file is not stored inside the broker
189: */
190: public function getFileReflection()
191: {
192: throw new Exception\BrokerException($this->getBroker(), sprintf('Constant %s was not parsed from a file', $this->getPrettyName()), Exception\BrokerException::UNSUPPORTED);
193: }
194:
195: /**
196: * Returns the definition start line number in the file.
197: *
198: * @return null
199: */
200: public function getStartLine()
201: {
202: return null;
203: }
204:
205: /**
206: * Returns the definition end line number in the file.
207: *
208: * @return null
209: */
210: public function getEndLine()
211: {
212: return null;
213: }
214:
215: /**
216: * Returns the appropriate docblock definition.
217: *
218: * @return boolean
219: */
220: public function getDocComment()
221: {
222: return false;
223: }
224:
225: /**
226: * Checks if there is a particular annotation.
227: *
228: * @param string $name Annotation name
229: * @return boolean
230: */
231: public function hasAnnotation($name)
232: {
233: return false;
234: }
235:
236: /**
237: * Returns a particular annotation value.
238: *
239: * @param string $name Annotation name
240: * @return null
241: */
242: public function getAnnotation($name)
243: {
244: return null;
245: }
246:
247: /**
248: * Returns parsed docblock.
249: *
250: * @return array
251: */
252: public function getAnnotations()
253: {
254: return array();
255: }
256:
257: /**
258: * Returns the constant value.
259: *
260: * @return mixed
261: */
262: public function getValue()
263: {
264: return null;
265: }
266:
267: /**
268: * Returns the part of the source code defining the constant value.
269: *
270: * @return string
271: */
272: public function getValueDefinition()
273: {
274: return null;
275: }
276:
277: /**
278: * Returns the originaly provided value definition.
279: *
280: * @return string
281: */
282: public function getOriginalValueDefinition()
283: {
284: return null;
285: }
286:
287: /**
288: * Returns if the constant is internal.
289: *
290: * @return boolean
291: */
292: public function isInternal()
293: {
294: return false;
295: }
296:
297: /**
298: * Returns if the constant is user defined.
299: *
300: * @return boolean
301: */
302: public function isUserDefined()
303: {
304: return true;
305: }
306:
307: /**
308: * Returns if the current reflection comes from a tokenized source.
309: *
310: * @return boolean
311: */
312: public function isTokenized()
313: {
314: return true;
315: }
316:
317: /**
318: * Returns if the reflection subject is deprecated.
319: *
320: * @return boolean
321: */
322: public function isDeprecated()
323: {
324: return false;
325: }
326:
327: /**
328: * Returns an element pretty (docblock compatible) name.
329: *
330: * @return string
331: */
332: public function getPrettyName()
333: {
334: return $this->name;
335: }
336:
337: /**
338: * Returns the string representation of the reflection object.
339: *
340: * @return string
341: */
342: public function __toString()
343: {
344: return sprintf(
345: "Constant [ %s %s ] { %s }\n",
346: gettype(null),
347: $this->getName(),
348: null
349: );
350: }
351:
352: /**
353: * Returns the reflection broker used by this reflection object.
354: *
355: * @return \TokenReflection\Broker
356: */
357: public function getBroker()
358: {
359: return $this->broker;
360: }
361:
362: /**
363: * Returns imported namespaces and aliases from the declaring namespace.
364: *
365: * @return array
366: */
367: public function getNamespaceAliases()
368: {
369: return array();
370: }
371:
372: /**
373: * Returns if the constant definition is valid.
374: *
375: * @return boolean
376: */
377: public function isValid()
378: {
379: return false;
380: }
381:
382: /**
383: * Magic __get method.
384: *
385: * @param string $key Variable name
386: * @return mixed
387: */
388: final public function __get($key)
389: {
390: return ReflectionBase::get($this, $key);
391: }
392:
393: /**
394: * Magic __isset method.
395: *
396: * @param string $key Variable name
397: * @return boolean
398: */
399: final public function __isset($key)
400: {
401: return ReflectionBase::exists($this, $key);
402: }
403: }
404: