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 | /** |
||
26 | * Create a new Property Instance |
||
27 | * |
||
28 | * @param string $name |
||
29 | * @param string $type |
||
30 | * @param string $default |
||
31 | */ |
||
32 | public function __construct(string $name, string $type = null, $default = null) |
||
38 | |||
39 | /** |
||
40 | * Set the property name |
||
41 | * @param string $name the name of the property |
||
42 | */ |
||
43 | public function setName(string $name) |
||
48 | |||
49 | /** |
||
50 | * Get the property name |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public function getName(): string |
||
58 | |||
59 | /** |
||
60 | * Set the type for the property |
||
61 | * |
||
62 | * @param string $type |
||
63 | * @todo add support for interface/class checking! |
||
64 | */ |
||
65 | public function setType($type) |
||
89 | |||
90 | /** |
||
91 | * Get the property type |
||
92 | * @return string|null |
||
93 | */ |
||
94 | public function getType() |
||
98 | |||
99 | /** |
||
100 | * Set the default value of the property if nothing is explicitly set |
||
101 | * |
||
102 | * @param mixed $default |
||
103 | */ |
||
104 | public function setDefault($default) |
||
108 | |||
109 | /** |
||
110 | * Get the default value |
||
111 | * |
||
112 | * @return mixed |
||
113 | */ |
||
114 | public function getDefault() |
||
118 | |||
119 | /** |
||
120 | * Set the value against the property |
||
121 | * |
||
122 | * @param mixed $value |
||
123 | */ |
||
124 | public function setValue($value) |
||
131 | |||
132 | /** |
||
133 | * Get the currently set value, if no value is set the default is used |
||
134 | * |
||
135 | * @return mixed |
||
136 | */ |
||
137 | public function getValue() |
||
149 | |||
150 | /** |
||
151 | * Inject a custom closure to handle the storage of the value when it is |
||
152 | * set into the property |
||
153 | * @param Closure $setter the custom function to run when the value is |
||
154 | * being set |
||
155 | * @return self |
||
156 | */ |
||
157 | public function setter(Closure $setter) |
||
163 | |||
164 | /** |
||
165 | * Specify a custom closer to handle the retreival of the value stored |
||
166 | * against this property |
||
167 | * |
||
168 | * @param Closure $getter [description] |
||
169 | * @return self |
||
170 | */ |
||
171 | public function getter(Closure $getter) |
||
177 | } |
||
178 |