1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Nette\Reflection;
13:
14: use Nette,
15: Nette\ObjectMixin;
16:
17:
18:
19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
56: class Method extends \ReflectionMethod
57: {
58:
59: 60: 61: 62: 63:
64: public static function from($class, $method)
65: {
66: return new static(is_object($class) ? get_class($class) : $class, $method);
67: }
68:
69:
70:
71: 72: 73:
74: public function toCallback()
75: {
76: return new Nette\Callback(parent::getDeclaringClass()->getName(), $this->getName());
77: }
78:
79:
80:
81: public function __toString()
82: {
83: return 'Method ' . parent::getDeclaringClass()->getName() . '::' . $this->getName() . '()';
84: }
85:
86:
87:
88:
89:
90:
91:
92: 93: 94:
95: public function getDeclaringClass()
96: {
97: return new ClassType(parent::getDeclaringClass()->getName());
98: }
99:
100:
101:
102: 103: 104:
105: public function getPrototype()
106: {
107: $prototype = parent::getPrototype();
108: return new Method($prototype->getDeclaringClass()->getName(), $prototype->getName());
109: }
110:
111:
112:
113: 114: 115:
116: public function getExtension()
117: {
118: return ($name = $this->getExtensionName()) ? new Extension($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 Parameter($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 = AnnotationsParser::getAll($this);
146: return !empty($res[$name]);
147: }
148:
149:
150:
151: 152: 153: 154: 155:
156: public function getAnnotation($name)
157: {
158: $res = AnnotationsParser::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 AnnotationsParser::getAll($this);
171: }
172:
173:
174:
175: 176: 177: 178:
179: public function getDescription()
180: {
181: return $this->getAnnotation('description');
182: }
183:
184:
185:
186:
187:
188:
189:
190: 191: 192:
193: public static function getReflection()
194: {
195: return new ClassType(get_called_class());
196: }
197:
198:
199:
200: public function __call($name, $args)
201: {
202: return ObjectMixin::call($this, $name, $args);
203: }
204:
205:
206:
207: public function &__get($name)
208: {
209: return ObjectMixin::get($this, $name);
210: }
211:
212:
213:
214: public function __set($name, $value)
215: {
216: return ObjectMixin::set($this, $name, $value);
217: }
218:
219:
220:
221: public function __isset($name)
222: {
223: return ObjectMixin::has($this, $name);
224: }
225:
226:
227:
228: public function __unset($name)
229: {
230: ObjectMixin::remove($this, $name);
231: }
232:
233: }
234: