1 | <?php |
||
15 | class Property |
||
16 | { |
||
17 | private $name; |
||
18 | private $type = null; |
||
19 | private $default = null; |
||
20 | private $value = null; |
||
21 | |||
22 | private $setter; |
||
23 | private $getter; |
||
24 | |||
25 | const TYPES = [ |
||
26 | 'string', |
||
27 | 'integer', |
||
28 | 'float', |
||
29 | 'boolean', |
||
30 | 'array', |
||
31 | 'object', |
||
32 | 30 | 'null', |
|
33 | 'resource', |
||
34 | 30 | ]; |
|
35 | 30 | ||
36 | 30 | /** |
|
37 | 30 | * Create a new Property Instance |
|
38 | * |
||
39 | * @param string $name |
||
40 | * @param string $type |
||
41 | * @param string $default |
||
42 | */ |
||
43 | 30 | public function __construct(string $name, string $type = null, $default = null) |
|
49 | |||
50 | /** |
||
51 | * Set the property name |
||
52 | * @param string $name the name of the property |
||
53 | */ |
||
54 | 3 | public function setName(string $name) |
|
59 | |||
60 | /** |
||
61 | * Get the property name |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | 30 | public function getName(): string |
|
69 | 27 | ||
70 | 27 | /** |
|
71 | * Set the type for the property |
||
72 | * |
||
73 | * @param string $type |
||
74 | 6 | * @todo add support for interface/class checking! |
|
75 | */ |
||
76 | public function setType($type) |
||
90 | |||
91 | /** |
||
92 | * Get the property type |
||
93 | * @return string|null |
||
94 | 3 | */ |
|
95 | public function getType() |
||
99 | |||
100 | /** |
||
101 | * Set the default value of the property if nothing is explicitly set |
||
102 | * |
||
103 | * @param mixed $default |
||
104 | 30 | */ |
|
105 | public function setDefault($default) |
||
109 | |||
110 | /** |
||
111 | * Get the default value |
||
112 | * |
||
113 | * @return mixed |
||
114 | 3 | */ |
|
115 | public function getDefault() |
||
119 | |||
120 | /** |
||
121 | * Set the value against the property |
||
122 | * |
||
123 | * @param mixed $value |
||
124 | 9 | */ |
|
125 | public function setValue($value) |
||
132 | |||
133 | /** |
||
134 | * Get the currently set value, if no value is set the default is used |
||
135 | * |
||
136 | * @return mixed |
||
137 | 12 | */ |
|
138 | public function getValue() |
||
150 | |||
151 | /** |
||
152 | * Inject a custom closure to handle the storage of the value when it is |
||
153 | * set into the property |
||
154 | * @param Closure $setter the custom function to run when the value is |
||
155 | * being set |
||
156 | * @return self |
||
157 | 3 | */ |
|
158 | public function setter(Closure $setter) |
||
164 | |||
165 | /** |
||
166 | * Specify a custom closer to handle the retreival of the value stored |
||
167 | * against this property |
||
168 | * |
||
169 | * @param Closure $getter [description] |
||
170 | * @return self |
||
171 | 3 | */ |
|
172 | public function getter(Closure $getter) |
||
178 | } |
||
179 |