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: 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: public function __call($name, $args)
114: {
115: return ObjectMixin::call($this, $name, $args);
116: }
117:
118:
119: public function &__get($name)
120: {
121: return ObjectMixin::get($this, $name);
122: }
123:
124:
125: public function __set($name, $value)
126: {
127: ObjectMixin::set($this, $name, $value);
128: }
129:
130:
131: public function __isset($name)
132: {
133: return ObjectMixin::has($this, $name);
134: }
135:
136:
137: public function __unset($name)
138: {
139: ObjectMixin::remove($this, $name);
140: }
141:
142: }
143: