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 | 4 | 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 | 6 | 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 mixed|null |
||
116 | * The method if it exists, null otherwise. |
||
117 | */ |
||
118 | 3 | 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 | 4 | public function doDynamicRequest(\Closure $func, array $parameters = [], $memoize = false) |
|
189 | |||
190 | /** |
||
191 | * @param $method |
||
192 | * @param array $parameters |
||
193 | * |
||
194 | * @return mixed |
||
195 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
196 | */ |
||
197 | 3 | public function __call($method, array $parameters = array()) |
|
205 | |||
206 | /** |
||
207 | * @param $method |
||
208 | * @param array $parameters |
||
209 | * |
||
210 | * @return mixed |
||
211 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
212 | */ |
||
213 | 1 | public static function __callStatic($method, array $parameters = array()) |
|
225 | |||
226 | /** |
||
227 | * {inheritdoc} |
||
228 | */ |
||
229 | 4 | public function __get($property) |
|
243 | |||
244 | /** |
||
245 | * {inheritdoc} |
||
246 | */ |
||
247 | 3 | public function __set($property, $value) |
|
253 | } |
||
254 |