1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14:
15: 16: 17: 18: 19: 20:
21: class NClassReflection 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) return NULL;
94: }
95:
96: $class = strtolower($this->getName());
97: $l = & self::$extMethods[strtolower($name)];
98:
99: if (empty($l)) {
100: return FALSE;
101:
102: } elseif (isset($l[''][$class])) {
103: return $l[''][$class];
104: }
105:
106: $cl = $class;
107: do {
108: if (isset($l[$cl])) {
109: return $l[''][$class] = $l[$cl];
110: }
111: } while (($cl = strtolower(get_parent_class($cl))) !== '');
112:
113: foreach (class_implements($class) as $cl) {
114: $cl = strtolower($cl);
115: if (isset($l[$cl])) {
116: return $l[''][$class] = $l[$cl];
117: }
118: }
119: return $l[''][$class] = FALSE;
120: }
121:
122:
123:
124:
125:
126:
127:
128: 129: 130:
131: public function getConstructor()
132: {
133: return ($ref = parent::getConstructor()) ? NMethodReflection::from($this->getName(), $ref->getName()) : NULL;
134: }
135:
136:
137:
138: 139: 140:
141: public function getExtension()
142: {
143: return ($name = $this->getExtensionName()) ? new NExtensionReflection($name) : NULL;
144: }
145:
146:
147:
148: public function getInterfaces()
149: {
150: $res = array();
151: foreach (parent::getInterfaceNames() as $val) {
152: $res[$val] = new self($val);
153: }
154: return $res;
155: }
156:
157:
158:
159: 160: 161:
162: public function getMethod($name)
163: {
164: return new NMethodReflection($this->getName(), $name);
165: }
166:
167:
168:
169: public function getMethods($filter = -1)
170: {
171: foreach ($res = parent::getMethods($filter) as $key => $val) {
172: $res[$key] = new NMethodReflection($this->getName(), $val->getName());
173: }
174: return $res;
175: }
176:
177:
178:
179: 180: 181:
182: public function getParentClass()
183: {
184: return ($ref = parent::getParentClass()) ? new self($ref->getName()) : NULL;
185: }
186:
187:
188:
189: public function getProperties($filter = -1)
190: {
191: foreach ($res = parent::getProperties($filter) as $key => $val) {
192: $res[$key] = new NPropertyReflection($this->getName(), $val->getName());
193: }
194: return $res;
195: }
196:
197:
198:
199: 200: 201:
202: public function getProperty($name)
203: {
204: return new NPropertyReflection($this->getName(), $name);
205: }
206:
207:
208:
209:
210:
211:
212:
213: 214: 215: 216: 217:
218: public function hasAnnotation($name)
219: {
220: $res = NAnnotationsParser::getAll($this);
221: return !empty($res[$name]);
222: }
223:
224:
225:
226: 227: 228: 229: 230:
231: public function getAnnotation($name)
232: {
233: $res = NAnnotationsParser::getAll($this);
234: return isset($res[$name]) ? end($res[$name]) : NULL;
235: }
236:
237:
238:
239: 240: 241: 242:
243: public function getAnnotations()
244: {
245: return NAnnotationsParser::getAll($this);
246: }
247:
248:
249:
250:
251:
252:
253:
254: 255: 256:
257: public function getReflection()
258: {
259: return new NClassReflection($this);
260: }
261:
262:
263:
264: public function __call($name, $args)
265: {
266: return NObjectMixin::call($this, $name, $args);
267: }
268:
269:
270:
271: public function &__get($name)
272: {
273: return NObjectMixin::get($this, $name);
274: }
275:
276:
277:
278: public function __set($name, $value)
279: {
280: return NObjectMixin::set($this, $name, $value);
281: }
282:
283:
284:
285: public function __isset($name)
286: {
287: return NObjectMixin::has($this, $name);
288: }
289:
290:
291:
292: public function __unset($name)
293: {
294: throw new MemberAccessException("Cannot unset the property {$this->reflection->name}::\$$name.");
295: }
296:
297: }
298: