1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Reflection;
9:
10: use Nette,
11: 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 'Parameter $' . parent::getName() . ' in ' . $this->getDeclaringFunction();
107: }
108:
109:
110:
111:
112:
113: 114: 115:
116: public static function getReflection()
117: {
118: return new ClassType(get_called_class());
119: }
120:
121:
122: public function __call($name, $args)
123: {
124: return ObjectMixin::call($this, $name, $args);
125: }
126:
127:
128: public function &__get($name)
129: {
130: return ObjectMixin::get($this, $name);
131: }
132:
133:
134: public function __set($name, $value)
135: {
136: ObjectMixin::set($this, $name, $value);
137: }
138:
139:
140: public function __isset($name)
141: {
142: return ObjectMixin::has($this, $name);
143: }
144:
145:
146: public function __unset($name)
147: {
148: ObjectMixin::remove($this, $name);
149: }
150:
151: }
152: