1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6: * @package Nette\Reflection
7: */
8:
9:
10:
11: /**
12: * Reports information about a method.
13: *
14: * @author David Grudl
15: * @property-read array $defaultParameters
16: * @property-read ClassReflection $declaringClass
17: * @property-read MethodReflection $prototype
18: * @property-read ExtensionReflection $extension
19: * @property-read ParameterReflection[] $parameters
20: * @property-read IAnnotation[][] $annotations
21: * @property-read string $description
22: * @property-read bool $public
23: * @property-read bool $private
24: * @property-read bool $protected
25: * @property-read bool $abstract
26: * @property-read bool $final
27: * @property-read bool $static
28: * @property-read bool $constructor
29: * @property-read bool $destructor
30: * @property-read int $modifiers
31: * @property-write bool $accessible
32: * @property-read bool $closure
33: * @property-read bool $deprecated
34: * @property-read bool $internal
35: * @property-read bool $userDefined
36: * @property-read string $docComment
37: * @property-read int $endLine
38: * @property-read string $extensionName
39: * @property-read string $fileName
40: * @property-read string $name
41: * @property-read string $namespaceName
42: * @property-read int $numberOfParameters
43: * @property-read int $numberOfRequiredParameters
44: * @property-read string $shortName
45: * @property-read int $startLine
46: * @property-read array $staticVariables
47: * @package Nette\Reflection
48: */
49: class MethodReflection extends ReflectionMethod
50: {
51:
52: /**
53: * @param string|object
54: * @param string
55: * @return MethodReflection
56: */
57: public static function from($class, $method)
58: {
59: return new self(is_object($class) ? get_class($class) : $class, $method);
60: }
61:
62:
63: /**
64: * @return Callback
65: */
66: public function toCallback()
67: {
68: return new Callback(parent::getDeclaringClass()->getName(), $this->getName());
69: }
70:
71:
72: public function __toString()
73: {
74: return 'Method ' . parent::getDeclaringClass()->getName() . '::' . $this->getName() . '()';
75: }
76:
77:
78: /********************* Reflection layer ****************d*g**/
79:
80:
81: /**
82: * @return ClassReflection
83: */
84: public function getDeclaringClass()
85: {
86: return new ClassReflection(parent::getDeclaringClass()->getName());
87: }
88:
89:
90: /**
91: * @return MethodReflection
92: */
93: public function getPrototype()
94: {
95: $prototype = parent::getPrototype();
96: return new MethodReflection($prototype->getDeclaringClass()->getName(), $prototype->getName());
97: }
98:
99:
100: /**
101: * @return ExtensionReflection
102: */
103: public function getExtension()
104: {
105: return ($name = $this->getExtensionName()) ? new ExtensionReflection($name) : NULL;
106: }
107:
108:
109: /**
110: * @return ParameterReflection[]
111: */
112: public function getParameters()
113: {
114: $me = array(parent::getDeclaringClass()->getName(), $this->getName());
115: foreach ($res = parent::getParameters() as $key => $val) {
116: $res[$key] = new ParameterReflection($me, $val->getName());
117: }
118: return $res;
119: }
120:
121:
122: /********************* Annotations support ****************d*g**/
123:
124:
125: /**
126: * Has method specified annotation?
127: * @param string
128: * @return bool
129: */
130: public function hasAnnotation($name)
131: {
132: $res = AnnotationsParser::getAll($this);
133: return !empty($res[$name]);
134: }
135:
136:
137: /**
138: * Returns an annotation value.
139: * @param string
140: * @return IAnnotation
141: */
142: public function getAnnotation($name)
143: {
144: $res = AnnotationsParser::getAll($this);
145: return isset($res[$name]) ? end($res[$name]) : NULL;
146: }
147:
148:
149: /**
150: * Returns all annotations.
151: * @return IAnnotation[][]
152: */
153: public function getAnnotations()
154: {
155: return AnnotationsParser::getAll($this);
156: }
157:
158:
159: /**
160: * Returns value of annotation 'description'.
161: * @return string
162: */
163: public function getDescription()
164: {
165: return $this->getAnnotation('description');
166: }
167:
168:
169: /********************* Object behaviour ****************d*g**/
170:
171:
172: /**
173: * @return ClassReflection
174: */
175: public function getReflection()
176: {
177: return new ClassReflection($this);
178: }
179:
180:
181: public function __call($name, $args)
182: {
183: return ObjectMixin::call($this, $name, $args);
184: }
185:
186:
187: public function &__get($name)
188: {
189: return ObjectMixin::get($this, $name);
190: }
191:
192:
193: public function __set($name, $value)
194: {
195: ObjectMixin::set($this, $name, $value);
196: }
197:
198:
199: public function __isset($name)
200: {
201: return ObjectMixin::has($this, $name);
202: }
203:
204:
205: public function __unset($name)
206: {
207: ObjectMixin::remove($this, $name);
208: }
209:
210: }
211: