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