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