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