1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Reflection;
9:
10: use Nette;
11: use Nette\ObjectMixin;
12:
13:
14: 15: 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: class Method extends \ReflectionMethod
52: {
53:
54: 55: 56: 57: 58:
59: public static function from($class, $method)
60: {
61: return new static(is_object($class) ? get_class($class) : $class, $method);
62: }
63:
64:
65: 66: 67:
68: public function toCallback()
69: {
70: return new Nette\Callback(parent::getDeclaringClass()->getName(), $this->getName());
71: }
72:
73:
74: public function __toString()
75: {
76: return parent::getDeclaringClass()->getName() . '::' . $this->getName() . '()';
77: }
78:
79:
80: public function getClosure($object = NULL)
81: {
82: return PHP_VERSION_ID < 50400
83: ? Nette\Utils\Callback::closure($object ?: parent::getDeclaringClass()->getName(), $this->getName())
84: : parent::getClosure($object);
85: }
86:
87:
88:
89:
90:
91: 92: 93:
94: public function getDeclaringClass()
95: {
96: return new ClassType(parent::getDeclaringClass()->getName());
97: }
98:
99:
100: 101: 102:
103: public function getPrototype()
104: {
105: $prototype = parent::getPrototype();
106: return new Method($prototype->getDeclaringClass()->getName(), $prototype->getName());
107: }
108:
109:
110: 111: 112:
113: public function getExtension()
114: {
115: return ($name = $this->getExtensionName()) ? new Extension($name) : NULL;
116: }
117:
118:
119: 120: 121:
122: public function getParameters()
123: {
124: $me = array(parent::getDeclaringClass()->getName(), $this->getName());
125: foreach ($res = parent::getParameters() as $key => $val) {
126: $res[$key] = new Parameter($me, $val->getName());
127: }
128: return $res;
129: }
130:
131:
132:
133:
134:
135: 136: 137: 138: 139:
140: public function hasAnnotation($name)
141: {
142: $res = AnnotationsParser::getAll($this);
143: return !empty($res[$name]);
144: }
145:
146:
147: 148: 149: 150: 151:
152: public function getAnnotation($name)
153: {
154: $res = AnnotationsParser::getAll($this);
155: return isset($res[$name]) ? end($res[$name]) : NULL;
156: }
157:
158:
159: 160: 161: 162:
163: public function getAnnotations()
164: {
165: return AnnotationsParser::getAll($this);
166: }
167:
168:
169: 170: 171: 172:
173: public function getDescription()
174: {
175: return $this->getAnnotation('description');
176: }
177:
178:
179:
180:
181:
182: 183: 184:
185: public static function getReflection()
186: {
187: trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
188: return new ClassType(get_called_class());
189: }
190:
191:
192: public function __call($name, $args)
193: {
194: return ObjectMixin::call($this, $name, $args);
195: }
196:
197:
198: public function &__get($name)
199: {
200: return ObjectMixin::get($this, $name);
201: }
202:
203:
204: public function __set($name, $value)
205: {
206: ObjectMixin::set($this, $name, $value);
207: }
208:
209:
210: public function __isset($name)
211: {
212: return ObjectMixin::has($this, $name);
213: }
214:
215:
216: public function __unset($name)
217: {
218: ObjectMixin::remove($this, $name);
219: }
220:
221: }
222: