1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: * @package Nette\Reflection
11: */
12:
13:
14:
15: /**
16: * Reports information about a method.
17: *
18: * @author David Grudl
19: * @property-read array $defaultParameters
20: * @property-read NClassReflection $declaringClass
21: * @property-read NMethodReflection $prototype
22: * @property-read NExtensionReflection $extension
23: * @property-read NParameterReflection[] $parameters
24: * @property-read IAnnotation[][] $annotations
25: * @property-read string $description
26: * @property-read bool $public
27: * @property-read bool $private
28: * @property-read bool $protected
29: * @property-read bool $abstract
30: * @property-read bool $final
31: * @property-read bool $static
32: * @property-read bool $constructor
33: * @property-read bool $destructor
34: * @property-read int $modifiers
35: * @property-write bool $accessible
36: * @property-read bool $closure
37: * @property-read bool $deprecated
38: * @property-read bool $internal
39: * @property-read bool $userDefined
40: * @property-read string $docComment
41: * @property-read int $endLine
42: * @property-read string $extensionName
43: * @property-read string $fileName
44: * @property-read string $name
45: * @property-read string $namespaceName
46: * @property-read int $numberOfParameters
47: * @property-read int $numberOfRequiredParameters
48: * @property-read string $shortName
49: * @property-read int $startLine
50: * @property-read array $staticVariables
51: * @package Nette\Reflection
52: */
53: class NMethodReflection extends ReflectionMethod
54: {
55:
56: /**
57: * @param string|object
58: * @param string
59: * @return NMethodReflection
60: */
61: public static function from($class, $method)
62: {
63: return new self(is_object($class) ? get_class($class) : $class, $method);
64: }
65:
66:
67:
68: /**
69: * @return NCallback
70: */
71: public function toCallback()
72: {
73: return new NCallback(parent::getDeclaringClass()->getName(), $this->getName());
74: }
75:
76:
77:
78: public function __toString()
79: {
80: return 'Method ' . parent::getDeclaringClass()->getName() . '::' . $this->getName() . '()';
81: }
82:
83:
84:
85: /********************* Reflection layer ****************d*g**/
86:
87:
88:
89: /**
90: * @return NClassReflection
91: */
92: public function getDeclaringClass()
93: {
94: return new NClassReflection(parent::getDeclaringClass()->getName());
95: }
96:
97:
98:
99: /**
100: * @return NMethodReflection
101: */
102: public function getPrototype()
103: {
104: $prototype = parent::getPrototype();
105: return new NMethodReflection($prototype->getDeclaringClass()->getName(), $prototype->getName());
106: }
107:
108:
109:
110: /**
111: * @return NExtensionReflection
112: */
113: public function getExtension()
114: {
115: return ($name = $this->getExtensionName()) ? new NExtensionReflection($name) : NULL;
116: }
117:
118:
119:
120: /**
121: * @return NParameterReflection[]
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: /********************* NAnnotations support ****************d*g**/
135:
136:
137:
138: /**
139: * Has method specified annotation?
140: * @param string
141: * @return bool
142: */
143: public function hasAnnotation($name)
144: {
145: $res = NAnnotationsParser::getAll($this);
146: return !empty($res[$name]);
147: }
148:
149:
150:
151: /**
152: * Returns an annotation value.
153: * @param string
154: * @return IAnnotation
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: * Returns all annotations.
166: * @return IAnnotation[][]
167: */
168: public function getAnnotations()
169: {
170: return NAnnotationsParser::getAll($this);
171: }
172:
173:
174:
175: /**
176: * Returns value of annotation 'description'.
177: * @return string
178: */
179: public function getDescription()
180: {
181: return $this->getAnnotation('description');
182: }
183:
184:
185:
186: /********************* NObject behaviour ****************d*g**/
187:
188:
189:
190: /**
191: * @return NClassReflection
192: */
193: public function getReflection()
194: {
195: return new NClassReflection($this);
196: }
197:
198:
199:
200: public function __call($name, $args)
201: {
202: return NObjectMixin::call($this, $name, $args);
203: }
204:
205:
206:
207: public function &__get($name)
208: {
209: return NObjectMixin::get($this, $name);
210: }
211:
212:
213:
214: public function __set($name, $value)
215: {
216: return NObjectMixin::set($this, $name, $value);
217: }
218:
219:
220:
221: public function __isset($name)
222: {
223: return NObjectMixin::has($this, $name);
224: }
225:
226:
227:
228: public function __unset($name)
229: {
230: NObjectMixin::remove($this, $name);
231: }
232:
233: }
234: