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: class GlobalFunction extends \ReflectionFunction
37: {
38:
39: private $value;
40:
41:
42: public function __construct($name)
43: {
44: parent::__construct($this->value = $name);
45: }
46:
47:
48: 49: 50:
51: public function toCallback()
52: {
53: return new Nette\Callback($this->value);
54: }
55:
56:
57: public function __toString()
58: {
59: return $this->getName() . '()';
60: }
61:
62:
63: public function getClosure()
64: {
65: return PHP_VERSION_ID < 50400
66: ? Nette\Utils\Callback::closure($this->value)
67: : parent::getClosure();
68: }
69:
70:
71:
72:
73:
74: 75: 76:
77: public function getExtension()
78: {
79: return ($name = $this->getExtensionName()) ? new Extension($name) : NULL;
80: }
81:
82:
83: 84: 85:
86: public function getParameters()
87: {
88: foreach ($res = parent::getParameters() as $key => $val) {
89: $res[$key] = new Parameter($this->value, $val->getName());
90: }
91: return $res;
92: }
93:
94:
95:
96:
97:
98: 99: 100: 101: 102:
103: public function hasAnnotation($name)
104: {
105: $res = AnnotationsParser::getAll($this);
106: return !empty($res[$name]);
107: }
108:
109:
110: 111: 112: 113: 114:
115: public function getAnnotation($name)
116: {
117: $res = AnnotationsParser::getAll($this);
118: return isset($res[$name]) ? end($res[$name]) : NULL;
119: }
120:
121:
122: 123: 124: 125:
126: public function getAnnotations()
127: {
128: return AnnotationsParser::getAll($this);
129: }
130:
131:
132: 133: 134: 135:
136: public function getDescription()
137: {
138: return $this->getAnnotation('description');
139: }
140:
141:
142:
143:
144:
145: public function __call($name, $args)
146: {
147: return ObjectMixin::call($this, $name, $args);
148: }
149:
150:
151: public function &__get($name)
152: {
153: return ObjectMixin::get($this, $name);
154: }
155:
156:
157: public function __set($name, $value)
158: {
159: ObjectMixin::set($this, $name, $value);
160: }
161:
162:
163: public function __isset($name)
164: {
165: return ObjectMixin::has($this, $name);
166: }
167:
168:
169: public function __unset($name)
170: {
171: ObjectMixin::remove($this, $name);
172: }
173:
174: }
175: