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 | protected $alreadyConstructed = false; |
||
54 | |||
55 | /** |
||
56 | * Check immutability. |
||
57 | * |
||
58 | * @throws ImmutabilityViolationException |
||
59 | */ |
||
60 | final protected function checkImmutability(): void |
||
75 | |||
76 | /** |
||
77 | * Check __construct method is called only once. |
||
78 | * |
||
79 | * @throws ImmutabilityViolationException |
||
80 | */ |
||
81 | final protected function checkConstructCall(): void |
||
92 | |||
93 | /** |
||
94 | * Check properties accessibility. |
||
95 | * |
||
96 | * @throws ImmutabilityViolationException |
||
97 | */ |
||
98 | final protected function checkPropertiesAccessibility(): void |
||
108 | |||
109 | /** |
||
110 | * Check methods accessibility. |
||
111 | * |
||
112 | * @throws ImmutabilityViolationException |
||
113 | */ |
||
114 | final protected function checkMethodsAccessibility(): void |
||
138 | |||
139 | /** |
||
140 | * Get list of defined public methods. |
||
141 | * |
||
142 | * @return string[] |
||
143 | */ |
||
144 | final protected function getClassPublicMethods(): array |
||
153 | |||
154 | /** |
||
155 | * Get list of allowed public methods. |
||
156 | * |
||
157 | * @return string[] |
||
158 | */ |
||
159 | protected function getAllowedPublicMethods(): array |
||
178 | |||
179 | /** |
||
180 | * Get a list of allowed interfaces to extract public methods from. |
||
181 | * |
||
182 | * @return string[] |
||
183 | */ |
||
184 | abstract protected function getAllowedInterfaces(): array; |
||
185 | |||
186 | /** |
||
187 | * @param string $method |
||
188 | * @param mixed[] $parameters |
||
189 | * |
||
190 | * @return mixed |
||
191 | */ |
||
192 | final public function __call(string $method, array $parameters) |
||
196 | |||
197 | /** |
||
198 | * @param string $name |
||
199 | * @param mixed $value |
||
200 | * |
||
201 | * @throws ImmutabilityViolationException |
||
202 | */ |
||
203 | final public function __set(string $name, $value): void |
||
207 | |||
208 | /** |
||
209 | * @param string $name |
||
210 | * |
||
211 | * @throws ImmutabilityViolationException |
||
212 | */ |
||
213 | final public function __unset(string $name): void |
||
217 | |||
218 | /** |
||
219 | * @throws ImmutabilityViolationException |
||
220 | */ |
||
221 | final public function __invoke(): void |
||
225 | } |
||
226 |