Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/src/Reflection/ReflectionConstant.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | 5fb285c0d0e3 |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
15:e200cb7efeb3 | 16:c2387f117808 |
---|---|
10 */ | 10 */ |
11 | 11 |
12 namespace Psy\Reflection; | 12 namespace Psy\Reflection; |
13 | 13 |
14 /** | 14 /** |
15 * Somehow the standard reflection library doesn't include constants. | 15 * @deprecated ReflectionConstant is now ReflectionClassConstant. This class |
16 * | 16 * name will be reclaimed in the next stable release, to be used for |
17 * ReflectionConstant corrects that omission. | 17 * ReflectionConstant_ :) |
18 */ | 18 */ |
19 class ReflectionConstant implements \Reflector | 19 class ReflectionConstant extends ReflectionClassConstant |
20 { | 20 { |
21 private $class; | |
22 private $name; | |
23 private $value; | |
24 | |
25 /** | 21 /** |
26 * Construct a ReflectionConstant object. | 22 * {inheritDoc}. |
27 * | |
28 * @param mixed $class | |
29 * @param string $name | |
30 */ | 23 */ |
31 public function __construct($class, $name) | 24 public function __construct($class, $name) |
32 { | 25 { |
33 if (!$class instanceof \ReflectionClass) { | 26 @trigger_error('ReflectionConstant is now ReflectionClassConstant', E_USER_DEPRECATED); |
34 $class = new \ReflectionClass($class); | |
35 } | |
36 | 27 |
37 $this->class = $class; | 28 parent::__construct($class, $name); |
38 $this->name = $name; | |
39 | |
40 $constants = $class->getConstants(); | |
41 if (!array_key_exists($name, $constants)) { | |
42 throw new \InvalidArgumentException('Unknown constant: ' . $name); | |
43 } | |
44 | |
45 $this->value = $constants[$name]; | |
46 } | |
47 | |
48 /** | |
49 * Gets the declaring class. | |
50 * | |
51 * @return string | |
52 */ | |
53 public function getDeclaringClass() | |
54 { | |
55 $parent = $this->class; | |
56 | |
57 // Since we don't have real reflection constants, we can't see where | |
58 // it's actually defined. Let's check for a constant that is also | |
59 // available on the parent class which has exactly the same value. | |
60 // | |
61 // While this isn't _technically_ correct, it's prolly close enough. | |
62 do { | |
63 $class = $parent; | |
64 $parent = $class->getParentClass(); | |
65 } while ($parent && $parent->hasConstant($this->name) && $parent->getConstant($this->name) === $this->value); | |
66 | |
67 return $class; | |
68 } | |
69 | |
70 /** | |
71 * Gets the constant name. | |
72 * | |
73 * @return string | |
74 */ | |
75 public function getName() | |
76 { | |
77 return $this->name; | |
78 } | |
79 | |
80 /** | |
81 * Gets the value of the constant. | |
82 * | |
83 * @return mixed | |
84 */ | |
85 public function getValue() | |
86 { | |
87 return $this->value; | |
88 } | |
89 | |
90 /** | |
91 * Gets the constant's file name. | |
92 * | |
93 * Currently returns null, because if it returns a file name the signature | |
94 * formatter will barf. | |
95 */ | |
96 public function getFileName() | |
97 { | |
98 return; | |
99 // return $this->class->getFileName(); | |
100 } | |
101 | |
102 /** | |
103 * Get the code start line. | |
104 * | |
105 * @throws \RuntimeException | |
106 */ | |
107 public function getStartLine() | |
108 { | |
109 throw new \RuntimeException('Not yet implemented because it\'s unclear what I should do here :)'); | |
110 } | |
111 | |
112 /** | |
113 * Get the code end line. | |
114 * | |
115 * @throws \RuntimeException | |
116 */ | |
117 public function getEndLine() | |
118 { | |
119 return $this->getStartLine(); | |
120 } | |
121 | |
122 /** | |
123 * Get the constant's docblock. | |
124 * | |
125 * @return false | |
126 */ | |
127 public function getDocComment() | |
128 { | |
129 return false; | |
130 } | |
131 | |
132 /** | |
133 * Export the constant? I don't think this is possible. | |
134 * | |
135 * @throws \RuntimeException | |
136 */ | |
137 public static function export() | |
138 { | |
139 throw new \RuntimeException('Not yet implemented because it\'s unclear what I should do here :)'); | |
140 } | |
141 | |
142 /** | |
143 * To string. | |
144 * | |
145 * @return string | |
146 */ | |
147 public function __toString() | |
148 { | |
149 return $this->getName(); | |
150 } | 29 } |
151 } | 30 } |