1 | <?php |
||
12 | trait DynamicObjectsTrait |
||
13 | { |
||
14 | use MemoizeTrait; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected static $dynamicMethods = array(); |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected static $dynamicProperties = array(); |
||
25 | |||
26 | /** |
||
27 | * Add a dynamic property. |
||
28 | * |
||
29 | * @param string $name |
||
30 | * The property name. |
||
31 | * @param mixed $value |
||
32 | * The property value. |
||
33 | * @param bool $memoize |
||
34 | * Memoize parameter. |
||
35 | */ |
||
36 | 5 | public static function addDynamicProperty($name, $value, $memoize = false) |
|
44 | |||
45 | /** |
||
46 | * Add a dynamic method. |
||
47 | * |
||
48 | * @param $name |
||
49 | * The method name. |
||
50 | * @param \Closure $func |
||
51 | * The method. |
||
52 | * @param bool $memoize |
||
53 | * Memoize parameter. |
||
54 | * @param bool $static |
||
55 | * Static flag parameter. |
||
56 | */ |
||
57 | 5 | public static function addDynamicMethod($name, \Closure $func, $memoize = false, $static = false) |
|
66 | |||
67 | /** |
||
68 | * Check if a dynamic property exists. |
||
69 | * |
||
70 | * @param string $name |
||
71 | * The property name. |
||
72 | * @return bool |
||
73 | * True if the property exists, false otherwise. |
||
74 | */ |
||
75 | 8 | public static function hasDynamicProperty($name) |
|
79 | |||
80 | /** |
||
81 | * Check if a dynamic method exists. |
||
82 | * |
||
83 | * @param string $name |
||
84 | * The property name. |
||
85 | * @return bool |
||
86 | * True if the property exists, false otherwise. |
||
87 | */ |
||
88 | 7 | public static function hasDynamicMethod($name) |
|
92 | |||
93 | /** |
||
94 | * Get a dynamic property. |
||
95 | * |
||
96 | * @param $name |
||
97 | * The property name. |
||
98 | * @return mixed|null |
||
99 | * The property value if it exists, null otherwise. |
||
100 | */ |
||
101 | 4 | public static function getDynamicProperty($name) |
|
109 | |||
110 | /** |
||
111 | * Get a dynamic method. |
||
112 | * |
||
113 | * @param $name |
||
114 | * The method name. |
||
115 | * @return array|null |
||
116 | * The method data if it exists, null otherwise. |
||
117 | */ |
||
118 | 4 | public static function getDynamicMethod($name) |
|
123 | |||
124 | /** |
||
125 | * Clear dynamic properties. |
||
126 | */ |
||
127 | 1 | public static function clearDynamicProperties() |
|
131 | |||
132 | /** |
||
133 | * Clear dynamic methods. |
||
134 | */ |
||
135 | 1 | public static function clearDynamicMethods() |
|
139 | |||
140 | /** |
||
141 | * Remove a dynamic property. |
||
142 | * |
||
143 | * @param string $name |
||
144 | * The property name. |
||
145 | */ |
||
146 | 1 | public static function removeDynamicProperty($name) |
|
150 | |||
151 | /** |
||
152 | * Remove a dynamic method. |
||
153 | * |
||
154 | * @param string $name |
||
155 | * The method name. |
||
156 | */ |
||
157 | 1 | public static function removeDynamicMethod($name) |
|
161 | |||
162 | /** |
||
163 | * Execute a closure. |
||
164 | * |
||
165 | * @param \Closure $func |
||
166 | * The closure. |
||
167 | * @param array $parameters |
||
168 | * The closure's parameters. |
||
169 | * @param bool $memoize |
||
170 | * The memoize parameter. |
||
171 | * |
||
172 | * @return mixed|null |
||
173 | * The return of the closure. |
||
174 | * |
||
175 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
176 | */ |
||
177 | 5 | public function doDynamicRequest(\Closure $func, array $parameters = [], $memoize = false) |
|
189 | |||
190 | /** |
||
191 | * Extend the dynamic object. |
||
192 | * |
||
193 | * @param $extensions |
||
194 | * A file that returns a callable or a callable. |
||
195 | * |
||
196 | * @return $this |
||
197 | * |
||
198 | * @throws \InvalidArgumentException |
||
199 | */ |
||
200 | 1 | public function extend($extensions) |
|
216 | |||
217 | /** |
||
218 | * @param $method |
||
219 | * @param array $parameters |
||
220 | * |
||
221 | * @return mixed |
||
222 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
223 | */ |
||
224 | 4 | public function __call($method, array $parameters = array()) |
|
232 | |||
233 | /** |
||
234 | * @param $method |
||
235 | * @param array $parameters |
||
236 | * |
||
237 | * @return mixed |
||
238 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
239 | */ |
||
240 | 2 | public static function __callStatic($method, array $parameters = array()) |
|
252 | |||
253 | /** |
||
254 | * {inheritdoc} |
||
255 | */ |
||
256 | 4 | public function __get($property) |
|
270 | |||
271 | /** |
||
272 | * {inheritdoc} |
||
273 | */ |
||
274 | 3 | public function __set($property, $value) |
|
280 | } |
||
281 |