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