1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14:
15: 16: 17: 18: 19: 20:
21: class ClassReflection extends ReflectionClass
22: {
23:
24:
25: private static $extMethods;
26:
27:
28:
29: 30: 31: 32:
33: public static function from($class)
34: {
35: return new self($class);
36: }
37:
38:
39:
40: public function __toString()
41: {
42: return 'Class ' . $this->getName();
43: }
44:
45:
46:
47: 48: 49:
50: public function hasEventProperty($name)
51: {
52: if (preg_match('#^on[A-Z]#', $name) && $this->hasProperty($name)) {
53: $rp = $this->getProperty($name);
54: return $rp->isPublic() && !$rp->isStatic();
55: }
56: return FALSE;
57: }
58:
59:
60:
61: 62: 63: 64: 65: 66:
67: public function setExtensionMethod($name, $callback)
68: {
69: $l = & self::$extMethods[strtolower($name)];
70: $l[strtolower($this->getName())] = callback($callback);
71: $l[''] = NULL;
72: return $this;
73: }
74:
75:
76:
77: 78: 79: 80: 81:
82: public function getExtensionMethod($name)
83: {
84: if (self::$extMethods === NULL || $name === NULL) {
85: $list = get_defined_functions();
86: foreach ($list['user'] as $fce) {
87: $pair = explode('_prototype_', $fce);
88: if (count($pair) === 2) {
89: self::$extMethods[$pair[1]][$pair[0]] = callback($fce);
90: self::$extMethods[$pair[1]][''] = NULL;
91: }
92: }
93: if ($name === NULL) {
94: return NULL;
95: }
96: }
97:
98: $class = strtolower($this->getName());
99: $l = & self::$extMethods[strtolower($name)];
100:
101: if (empty($l)) {
102: return FALSE;
103:
104: } elseif (isset($l[''][$class])) {
105: return $l[''][$class];
106: }
107:
108: $cl = $class;
109: do {
110: if (isset($l[$cl])) {
111: return $l[''][$class] = $l[$cl];
112: }
113: } while (($cl = strtolower(get_parent_class($cl))) !== '');
114:
115: foreach (class_implements($class) as $cl) {
116: $cl = strtolower($cl);
117: if (isset($l[$cl])) {
118: return $l[''][$class] = $l[$cl];
119: }
120: }
121: return $l[''][$class] = FALSE;
122: }
123:
124:
125:
126:
127:
128:
129:
130: 131: 132:
133: public function getConstructor()
134: {
135: return ($ref = parent::getConstructor()) ? MethodReflection::from($this->getName(), $ref->getName()) : NULL;
136: }
137:
138:
139:
140: 141: 142:
143: public function getExtension()
144: {
145: return ($name = $this->getExtensionName()) ? new ExtensionReflection($name) : NULL;
146: }
147:
148:
149:
150: public function getInterfaces()
151: {
152: $res = array();
153: foreach (parent::getInterfaceNames() as $val) {
154: $res[$val] = new self($val);
155: }
156: return $res;
157: }
158:
159:
160:
161: 162: 163:
164: public function getMethod($name)
165: {
166: return new MethodReflection($this->getName(), $name);
167: }
168:
169:
170:
171: public function getMethods($filter = -1)
172: {
173: foreach ($res = parent::getMethods($filter) as $key => $val) {
174: $res[$key] = new MethodReflection($this->getName(), $val->getName());
175: }
176: return $res;
177: }
178:
179:
180:
181: 182: 183:
184: public function getParentClass()
185: {
186: return ($ref = parent::getParentClass()) ? new self($ref->getName()) : NULL;
187: }
188:
189:
190:
191: public function getProperties($filter = -1)
192: {
193: foreach ($res = parent::getProperties($filter) as $key => $val) {
194: $res[$key] = new PropertyReflection($this->getName(), $val->getName());
195: }
196: return $res;
197: }
198:
199:
200:
201: 202: 203:
204: public function getProperty($name)
205: {
206: return new PropertyReflection($this->getName(), $name);
207: }
208:
209:
210:
211:
212:
213:
214:
215: 216: 217: 218: 219:
220: public function hasAnnotation($name)
221: {
222: $res = AnnotationsParser::getAll($this);
223: return !empty($res[$name]);
224: }
225:
226:
227:
228: 229: 230: 231: 232:
233: public function getAnnotation($name)
234: {
235: $res = AnnotationsParser::getAll($this);
236: return isset($res[$name]) ? end($res[$name]) : NULL;
237: }
238:
239:
240:
241: 242: 243: 244:
245: public function getAnnotations()
246: {
247: return AnnotationsParser::getAll($this);
248: }
249:
250:
251:
252: 253: 254: 255:
256: public function getDescription()
257: {
258: return $this->getAnnotation('description');
259: }
260:
261:
262:
263:
264:
265:
266:
267: 268: 269:
270: public function getReflection()
271: {
272: return new ClassReflection($this);
273: }
274:
275:
276:
277: public function __call($name, $args)
278: {
279: return ObjectMixin::call($this, $name, $args);
280: }
281:
282:
283:
284: public function &__get($name)
285: {
286: return ObjectMixin::get($this, $name);
287: }
288:
289:
290:
291: public function __set($name, $value)
292: {
293: return ObjectMixin::set($this, $name, $value);
294: }
295:
296:
297:
298: public function __isset($name)
299: {
300: return ObjectMixin::has($this, $name);
301: }
302:
303:
304:
305: public function __unset($name)
306: {
307: ObjectMixin::remove($this, $name);
308: }
309:
310: }
311: