1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14:
15: 16: 17: 18: 19:
20: class NMethodReflection extends ReflectionMethod
21: {
22:
23: 24: 25: 26: 27:
28: public static function from($class, $method)
29: {
30: return new self(is_object($class) ? get_class($class) : $class, $method);
31: }
32:
33:
34:
35: 36: 37:
38: public function getDefaultParameters()
39: {
40: $res = array();
41: foreach (parent::getParameters() as $param) {
42: $res[$param->getName()] = $param->isDefaultValueAvailable()
43: ? $param->getDefaultValue()
44: : NULL;
45:
46: if ($param->isArray()) {
47: settype($res[$param->getName()], 'array');
48: }
49: }
50: return $res;
51: }
52:
53:
54:
55: 56: 57: 58: 59: 60:
61: public function invokeNamedArgs($object, $args)
62: {
63: $res = array();
64: $i = 0;
65: foreach ($this->getDefaultParameters() as $name => $def) {
66: if (isset($args[$name])) { 67: $val = $args[$name];
68: if ($def !== NULL) {
69: settype($val, gettype($def));
70: }
71: $res[$i++] = $val;
72: } else {
73: $res[$i++] = $def;
74: }
75: }
76: return $this->invokeArgs($object, $res);
77: }
78:
79:
80:
81: 82: 83:
84: public function getCallback()
85: {
86: return new NCallback(parent::getDeclaringClass()->getName(), $this->getName());
87: }
88:
89:
90:
91: public function __toString()
92: {
93: return 'Method ' . parent::getDeclaringClass()->getName() . '::' . $this->getName() . '()';
94: }
95:
96:
97:
98:
99:
100:
101:
102: 103: 104:
105: public function getDeclaringClass()
106: {
107: return new NClassReflection(parent::getDeclaringClass()->getName());
108: }
109:
110:
111:
112: 113: 114:
115: public function getPrototype()
116: {
117: $prototype = parent::getPrototype();
118: return new NMethodReflection($prototype->getDeclaringClass()->getName(), $prototype->getName());
119: }
120:
121:
122:
123: 124: 125:
126: public function getExtension()
127: {
128: return ($name = $this->getExtensionName()) ? new NExtensionReflection($name) : NULL;
129: }
130:
131:
132:
133: public function getParameters()
134: {
135: $me = array(parent::getDeclaringClass()->getName(), $this->getName());
136: foreach ($res = parent::getParameters() as $key => $val) {
137: $res[$key] = new NParameterReflection($me, $val->getName());
138: }
139: return $res;
140: }
141:
142:
143:
144:
145:
146:
147:
148: 149: 150: 151: 152:
153: public function hasAnnotation($name)
154: {
155: $res = NAnnotationsParser::getAll($this);
156: return !empty($res[$name]);
157: }
158:
159:
160:
161: 162: 163: 164: 165:
166: public function getAnnotation($name)
167: {
168: $res = NAnnotationsParser::getAll($this);
169: return isset($res[$name]) ? end($res[$name]) : NULL;
170: }
171:
172:
173:
174: 175: 176: 177:
178: public function getAnnotations()
179: {
180: return NAnnotationsParser::getAll($this);
181: }
182:
183:
184:
185:
186:
187:
188:
189: 190: 191:
192: public function getReflection()
193: {
194: return new NClassReflection($this);
195: }
196:
197:
198:
199: public function __call($name, $args)
200: {
201: return NObjectMixin::call($this, $name, $args);
202: }
203:
204:
205:
206: public function &__get($name)
207: {
208: return NObjectMixin::get($this, $name);
209: }
210:
211:
212:
213: public function __set($name, $value)
214: {
215: return NObjectMixin::set($this, $name, $value);
216: }
217:
218:
219:
220: public function __isset($name)
221: {
222: return NObjectMixin::has($this, $name);
223: }
224:
225:
226:
227: public function __unset($name)
228: {
229: NObjectMixin::remove($this, $name);
230: }
231:
232: }
233: