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