1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Benoth\StaticReflection\Reflection; |
4
|
|
|
|
5
|
|
|
class ReflectionProperty extends Reflection |
6
|
|
|
{ |
7
|
|
|
use Parts\VisibilityTrait; |
8
|
|
|
use Parts\StaticTrait; |
9
|
|
|
use Parts\DeclaringClassLikeTrait; |
10
|
|
|
use Parts\DocCommentTrait; |
11
|
|
|
|
12
|
|
|
protected $defaultType = 'null'; |
13
|
|
|
protected $defaultValue = null; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Gets the property's default type and value. |
17
|
|
|
* |
18
|
|
|
* @return array Type at index 0 and Value at index 1 |
19
|
|
|
*/ |
20
|
3 |
|
public function getDefault() |
21
|
|
|
{ |
22
|
3 |
|
return [$this->defaultType, $this->defaultValue]; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Gets the property's default type. |
27
|
|
|
* |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
3 |
|
public function getDefaultType() |
31
|
|
|
{ |
32
|
3 |
|
return $this->defaultType; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Gets the property's default value. |
37
|
|
|
* |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
21 |
|
public function getDefaultValue() |
41
|
|
|
{ |
42
|
21 |
|
return $this->defaultValue; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Sets the property's default value and type. |
47
|
|
|
* |
48
|
|
|
* @param string $type |
49
|
|
|
* @param mixed $value |
50
|
|
|
*/ |
51
|
786 |
|
public function setDefault($type, $value) |
52
|
|
|
{ |
53
|
786 |
|
$this->defaultType = $type; |
54
|
786 |
|
$this->defaultValue = $value; |
55
|
|
|
|
56
|
786 |
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Gets the property's value. |
61
|
|
|
* |
62
|
|
|
* @param object $object If the property is non-static an object must be provided to fetch the property from |
63
|
|
|
* |
64
|
|
|
* @throws \ReflectionException If something is received in parameter |
65
|
|
|
* |
66
|
|
|
* @return mixed |
67
|
|
|
*/ |
68
|
|
|
public function getValue($object = null) |
69
|
|
|
{ |
70
|
|
|
if (!is_null($object)) { |
71
|
|
|
throw new \ReflectionException('StaticReflection can\'t fetch objects'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $this->getDefaultValue(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Checks whether the property was declared at compile-time or was dynamically declared at run-time. |
79
|
|
|
* |
80
|
|
|
* @return bool If the property was declared at compile-time |
81
|
|
|
*/ |
82
|
|
|
public function isDefault() |
83
|
|
|
{ |
84
|
|
|
return true; // There's no instanciation with static reflection, so the property is always set at compile time |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Set property accessibility. |
89
|
|
|
* |
90
|
|
|
* @param bool $accessible |
91
|
|
|
* |
92
|
|
|
* @throws \ReflectionException Always... Can't be implemented |
93
|
|
|
* |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
|
|
public function setAccessible($accessible) |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
throw new \ReflectionException('StaticReflection can\'t change property accessibility'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Set property value. |
103
|
|
|
* |
104
|
|
|
* @param mixed $objectOrValue |
105
|
|
|
* @param mixed $value |
106
|
|
|
* |
107
|
|
|
* @throws \ReflectionException Always... Can't be implemented |
108
|
|
|
*/ |
109
|
|
|
public function setValue($objectOrValue, $value = null) |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
throw new \ReflectionException('StaticReflection can\'t change a property value'); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.