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