1 | <?php |
||
21 | trait ImmutabilityBehaviour |
||
22 | { |
||
23 | /** |
||
24 | * Class immutability checked map. |
||
25 | * |
||
26 | * @var bool[] |
||
27 | */ |
||
28 | protected static $immutabilityCheckMap = []; |
||
29 | |||
30 | /** |
||
31 | * List of default allowed magic methods. |
||
32 | * |
||
33 | * @var string[] |
||
34 | */ |
||
35 | protected static $allowedMagicMethods = [ |
||
36 | '__construct', |
||
37 | '__destruct', |
||
38 | '__get', |
||
39 | '__isset', |
||
40 | '__sleep', |
||
41 | '__wakeup', |
||
42 | '__toString', |
||
43 | '__set_state', |
||
44 | '__clone', |
||
45 | '__debugInfo', |
||
46 | ]; |
||
47 | |||
48 | /** |
||
49 | * Single constructor call check. |
||
50 | * |
||
51 | * @var bool |
||
52 | */ |
||
53 | private $alreadyConstructed = false; |
||
54 | |||
55 | /** |
||
56 | * Check immutability. |
||
57 | * |
||
58 | * @throws ImmutabilityViolationException |
||
59 | */ |
||
60 | final protected function checkImmutability(): void |
||
75 | |||
76 | /** |
||
77 | * Check __construct method constraints. |
||
78 | * |
||
79 | * @throws ImmutabilityViolationException |
||
80 | */ |
||
81 | private function checkCallConstraints(): void |
||
105 | |||
106 | /** |
||
107 | * Check properties accessibility. |
||
108 | * |
||
109 | * @throws ImmutabilityViolationException |
||
110 | */ |
||
111 | private function checkPropertiesAccessibility(): void |
||
121 | |||
122 | /** |
||
123 | * Check methods accessibility. |
||
124 | * |
||
125 | * @throws ImmutabilityViolationException |
||
126 | */ |
||
127 | private function checkMethodsAccessibility(): void |
||
151 | |||
152 | /** |
||
153 | * Get list of defined public methods. |
||
154 | * |
||
155 | * @return string[] |
||
156 | */ |
||
157 | private function getClassPublicMethods(): array |
||
166 | |||
167 | /** |
||
168 | * Get list of allowed public methods. |
||
169 | * |
||
170 | * @return string[] |
||
171 | */ |
||
172 | protected function getAllowedPublicMethods(): array |
||
191 | |||
192 | /** |
||
193 | * Get a list of allowed interfaces to extract public methods from. |
||
194 | * |
||
195 | * @return string[] |
||
196 | */ |
||
197 | abstract protected function getAllowedInterfaces(): array; |
||
198 | |||
199 | /** |
||
200 | * @param string $method |
||
201 | * @param mixed[] $parameters |
||
202 | * |
||
203 | * @return mixed |
||
204 | */ |
||
205 | final public function __call(string $method, array $parameters) |
||
209 | |||
210 | /** |
||
211 | * @param string $name |
||
212 | * @param mixed $value |
||
213 | * |
||
214 | * @throws ImmutabilityViolationException |
||
215 | */ |
||
216 | final public function __set(string $name, $value): void |
||
220 | |||
221 | /** |
||
222 | * @param string $name |
||
223 | * |
||
224 | * @throws ImmutabilityViolationException |
||
225 | */ |
||
226 | final public function __unset(string $name): void |
||
230 | |||
231 | /** |
||
232 | * @throws ImmutabilityViolationException |
||
233 | */ |
||
234 | final public function __invoke(): void |
||
238 | } |
||
239 |