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: class Parameter extends \ReflectionParameter
35: {
36:
37: private $function;
38:
39:
40: public function __construct($function, $parameter)
41: {
42: parent::__construct($this->function = $function, $parameter);
43: }
44:
45:
46: 47: 48:
49: public function getClass()
50: {
51: return ($ref = parent::getClass()) ? new ClassType($ref->getName()) : NULL;
52: }
53:
54:
55: 56: 57:
58: public function getClassName()
59: {
60: try {
61: return ($ref = parent::getClass()) ? $ref->getName() : NULL;
62: } catch (\ReflectionException $e) {
63: if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
64: return $m[1];
65: }
66: throw $e;
67: }
68: }
69:
70:
71: 72: 73:
74: public function getDeclaringClass()
75: {
76: return ($ref = parent::getDeclaringClass()) ? new ClassType($ref->getName()) : NULL;
77: }
78:
79:
80: 81: 82:
83: public function getDeclaringFunction()
84: {
85: return is_array($this->function)
86: ? new Method($this->function[0], $this->function[1])
87: : new GlobalFunction($this->function);
88: }
89:
90:
91: 92: 93:
94: public function isDefaultValueAvailable()
95: {
96: if (PHP_VERSION_ID === 50316) {
97: try {
98: $this->getDefaultValue();
99: return TRUE;
100: } catch (\ReflectionException $e) {
101: return FALSE;
102: }
103: }
104: return parent::isDefaultValueAvailable();
105: }
106:
107:
108: public function __toString()
109: {
110: return 'Parameter $' . parent::getName() . ' in ' . $this->getDeclaringFunction();
111: }
112:
113:
114:
115:
116:
117: 118: 119:
120: public static function getReflection()
121: {
122: return new ClassType(get_called_class());
123: }
124:
125:
126: public function __call($name, $args)
127: {
128: return ObjectMixin::call($this, $name, $args);
129: }
130:
131:
132: public function &__get($name)
133: {
134: return ObjectMixin::get($this, $name);
135: }
136:
137:
138: public function __set($name, $value)
139: {
140: return ObjectMixin::set($this, $name, $value);
141: }
142:
143:
144: public function __isset($name)
145: {
146: return ObjectMixin::has($this, $name);
147: }
148:
149:
150: public function __unset($name)
151: {
152: ObjectMixin::remove($this, $name);
153: }
154:
155: }
156: