1 | <?php |
||
13 | trait DynamicObjectsTrait |
||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | protected static $dynamicMethods = array(); |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected static $dynamicProperties = array(); |
||
24 | |||
25 | /** |
||
26 | * @var CacheInterface |
||
27 | */ |
||
28 | protected static $cache; |
||
29 | |||
30 | /** |
||
31 | * Add a dynamic property. |
||
32 | * |
||
33 | * @param string $name |
||
34 | * The property name. |
||
35 | * @param mixed $value |
||
36 | * The property value. |
||
37 | * @param bool $memoize |
||
38 | * Memoize parameter. |
||
39 | */ |
||
40 | 5 | public static function addDynamicProperty($name, $value, $memoize = false) |
|
48 | |||
49 | /** |
||
50 | * Add a dynamic method. |
||
51 | * |
||
52 | * @param $name |
||
53 | * The method name. |
||
54 | * @param \Closure $func |
||
55 | * The method. |
||
56 | * @param bool $memoize |
||
57 | * Memoize parameter. |
||
58 | */ |
||
59 | 4 | public static function addDynamicMethod($name, \Closure $func, $memoize = false) |
|
67 | |||
68 | /** |
||
69 | * Check if a dynamic property exists. |
||
70 | * |
||
71 | * @param string $name |
||
72 | * The property name. |
||
73 | * @return bool |
||
74 | * True if the property exists, false otherwise. |
||
75 | */ |
||
76 | 8 | public static function hasDynamicProperty($name) |
|
80 | |||
81 | /** |
||
82 | * Check if a dynamic method exists. |
||
83 | * |
||
84 | * @param string $name |
||
85 | * The property name. |
||
86 | * @return bool |
||
87 | * True if the property exists, false otherwise. |
||
88 | */ |
||
89 | 6 | public static function hasDynamicMethod($name) |
|
93 | |||
94 | /** |
||
95 | * Get a dynamic property. |
||
96 | * |
||
97 | * @param $name |
||
98 | * The property name. |
||
99 | * @return mixed|null |
||
100 | * The property value if it exists, null otherwise. |
||
101 | */ |
||
102 | 4 | public static function getDynamicProperty($name) |
|
110 | |||
111 | /** |
||
112 | * Get a dynamic method. |
||
113 | * |
||
114 | * @param $name |
||
115 | * The method name. |
||
116 | * @return mixed|null |
||
117 | * The method if it exists, null otherwise. |
||
118 | */ |
||
119 | 2 | public static function getDynamicMethod($name) |
|
124 | |||
125 | /** |
||
126 | * Clear dynamic properties. |
||
127 | */ |
||
128 | 1 | public static function clearDynamicProperties() |
|
132 | |||
133 | /** |
||
134 | * Clear dynamic methods. |
||
135 | */ |
||
136 | 1 | public static function clearDynamicMethods() |
|
140 | |||
141 | /** |
||
142 | * Remove a dynamic property. |
||
143 | * |
||
144 | * @param string $name |
||
145 | * The property name. |
||
146 | */ |
||
147 | 1 | public static function removeDynamicProperty($name) |
|
151 | |||
152 | /** |
||
153 | * Remove a dynamic method. |
||
154 | * |
||
155 | * @param string $name |
||
156 | * The method name. |
||
157 | */ |
||
158 | 1 | public static function removeDynamicMethod($name) |
|
162 | |||
163 | /** |
||
164 | * Set the cache. |
||
165 | * |
||
166 | * @param \Psr\SimpleCache\CacheInterface $cache |
||
167 | */ |
||
168 | 3 | public static function setDynamicObjectCacheProvider(CacheInterface $cache) |
|
172 | |||
173 | /** |
||
174 | * Get the cache. |
||
175 | * |
||
176 | * @return \Psr\SimpleCache\CacheInterface |
||
177 | */ |
||
178 | 4 | public static function getDynamicObjectCacheProvider() |
|
186 | |||
187 | /** |
||
188 | * Clear the cache. |
||
189 | */ |
||
190 | 1 | public static function clearDynamicObjectCache() |
|
194 | |||
195 | /** |
||
196 | * Execute a closure. |
||
197 | * |
||
198 | * @param \Closure $func |
||
199 | * The closure. |
||
200 | * @param array $parameters |
||
201 | * The closure's parameters. |
||
202 | * @param bool $memoize |
||
203 | * The memoize parameter. |
||
204 | * |
||
205 | * @return mixed|null |
||
206 | * The return of the closure. |
||
207 | */ |
||
208 | 4 | private function request(\Closure $func, array $parameters = [], $memoize = false) |
|
226 | |||
227 | /** |
||
228 | * @param $method |
||
229 | * @param array $parameters |
||
230 | * |
||
231 | * @return mixed |
||
232 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
233 | */ |
||
234 | 3 | public function __call($method, array $parameters = array()) |
|
243 | |||
244 | /** |
||
245 | * {inheritdoc} |
||
246 | */ |
||
247 | 4 | public function __get($property) |
|
262 | |||
263 | /** |
||
264 | * {inheritdoc} |
||
265 | */ |
||
266 | 3 | public function __set($property, $value) |
|
272 | } |
||
273 |