1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Nette\Reflection;
13:
14: use Nette,
15: Nette\ObjectMixin;
16:
17:
18:
19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34:
35: class Parameter extends \ReflectionParameter
36: {
37:
38: private $function;
39:
40:
41: public function __construct($function, $parameter)
42: {
43: parent::__construct($this->function = $function, $parameter);
44: }
45:
46:
47:
48: 49: 50:
51: public function getClass()
52: {
53: return ($ref = parent::getClass()) ? new ClassType($ref->getName()) : NULL;
54: }
55:
56:
57:
58: 59: 60:
61: public function getClassName()
62: {
63: try {
64: return ($ref = parent::getClass()) ? $ref->getName() : NULL;
65: } catch (\ReflectionException $e) {
66: if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
67: return $m[1];
68: }
69: throw $e;
70: }
71: }
72:
73:
74:
75: 76: 77:
78: public function getDeclaringClass()
79: {
80: return ($ref = parent::getDeclaringClass()) ? new ClassType($ref->getName()) : NULL;
81: }
82:
83:
84:
85: 86: 87:
88: public function getDeclaringFunction()
89: {
90: return is_array($this->function)
91: ? new Method($this->function[0], $this->function[1])
92: : new GlobalFunction($this->function);
93: }
94:
95:
96:
97: 98: 99:
100: public function isDefaultValueAvailable()
101: {
102: if (PHP_VERSION_ID === 50316) {
103: try {
104: $this->getDefaultValue();
105: return TRUE;
106: } catch (\ReflectionException $e) {
107: return FALSE;
108: }
109: }
110: return parent::isDefaultValueAvailable();
111: }
112:
113:
114:
115: public function __toString()
116: {
117: return 'Parameter $' . parent::getName() . ' in ' . $this->getDeclaringFunction();
118: }
119:
120:
121:
122:
123:
124:
125:
126: 127: 128:
129: public static function getReflection()
130: {
131: return new ClassType(get_called_class());
132: }
133:
134:
135:
136: public function __call($name, $args)
137: {
138: return ObjectMixin::call($this, $name, $args);
139: }
140:
141:
142:
143: public function &__get($name)
144: {
145: return ObjectMixin::get($this, $name);
146: }
147:
148:
149:
150: public function __set($name, $value)
151: {
152: return ObjectMixin::set($this, $name, $value);
153: }
154:
155:
156:
157: public function __isset($name)
158: {
159: return ObjectMixin::has($this, $name);
160: }
161:
162:
163:
164: public function __unset($name)
165: {
166: ObjectMixin::remove($this, $name);
167: }
168:
169: }
170: