1 | <?php |
||
14 | trait DynamicObjectsTrait |
||
15 | { |
||
16 | use MemoizeTrait; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected static $dynamicMethods = array(); |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | protected static $dynamicProperties = array(); |
||
27 | |||
28 | /** |
||
29 | * Add a dynamic property. |
||
30 | * |
||
31 | * @param string $name |
||
32 | * The property name. |
||
33 | * @param mixed $value |
||
34 | * The property value. |
||
35 | * @param bool $memoize |
||
36 | * Memoize parameter. |
||
37 | */ |
||
38 | public static function addDynamicProperty($name, $value, $memoize = false) |
||
46 | |||
47 | 5 | /** |
|
48 | * Add a dynamic method. |
||
49 | * |
||
50 | * @param $name |
||
51 | * The method name. |
||
52 | * @param \Closure $func |
||
53 | * The method. |
||
54 | * @param bool $memoize |
||
55 | * Memoize parameter. |
||
56 | */ |
||
57 | public static function addDynamicMethod($name, \Closure $func, $memoize = false) |
||
65 | |||
66 | 4 | /** |
|
67 | * Check if a dynamic property exists. |
||
68 | * |
||
69 | * @param string $name |
||
70 | * The property name. |
||
71 | * @return bool |
||
72 | * True if the property exists, false otherwise. |
||
73 | */ |
||
74 | public static function hasDynamicProperty($name) |
||
78 | 8 | ||
79 | /** |
||
80 | * Check if a dynamic method exists. |
||
81 | * |
||
82 | * @param string $name |
||
83 | * The property name. |
||
84 | * @return bool |
||
85 | * True if the property exists, false otherwise. |
||
86 | */ |
||
87 | public static function hasDynamicMethod($name) |
||
91 | 6 | ||
92 | /** |
||
93 | * Get a dynamic property. |
||
94 | * |
||
95 | * @param $name |
||
96 | * The property name. |
||
97 | * @return mixed|null |
||
98 | * The property value if it exists, null otherwise. |
||
99 | */ |
||
100 | public static function getDynamicProperty($name) |
||
108 | 1 | ||
109 | /** |
||
110 | * Get a dynamic method. |
||
111 | * |
||
112 | * @param $name |
||
113 | * The method name. |
||
114 | * @return mixed|null |
||
115 | * The method if it exists, null otherwise. |
||
116 | */ |
||
117 | public static function getDynamicMethod($name) |
||
122 | 2 | ||
123 | /** |
||
124 | * Clear dynamic properties. |
||
125 | */ |
||
126 | public static function clearDynamicProperties() |
||
130 | 1 | ||
131 | 1 | /** |
|
132 | * Clear dynamic methods. |
||
133 | */ |
||
134 | public static function clearDynamicMethods() |
||
138 | 1 | ||
139 | 1 | /** |
|
140 | * Remove a dynamic property. |
||
141 | * |
||
142 | * @param string $name |
||
143 | * The property name. |
||
144 | */ |
||
145 | public static function removeDynamicProperty($name) |
||
149 | 1 | ||
150 | 1 | /** |
|
151 | * Remove a dynamic method. |
||
152 | * |
||
153 | * @param string $name |
||
154 | * The method name. |
||
155 | */ |
||
156 | public static function removeDynamicMethod($name) |
||
160 | 1 | ||
161 | 1 | /** |
|
162 | * Execute a closure. |
||
163 | * |
||
164 | * @param \Closure $func |
||
165 | * The closure. |
||
166 | * @param array $parameters |
||
167 | * The closure's parameters. |
||
168 | 3 | * @param bool $memoize |
|
169 | * The memoize parameter. |
||
170 | 3 | * |
|
171 | 3 | * @return mixed|null |
|
172 | * The return of the closure. |
||
173 | * |
||
174 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
175 | */ |
||
176 | public function doDynamicRequest(\Closure $func, array $parameters = [], $memoize = false) |
||
188 | |||
189 | /** |
||
190 | 1 | * @param $method |
|
191 | * @param array $parameters |
||
192 | 1 | * |
|
193 | 1 | * @return mixed |
|
194 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
195 | */ |
||
196 | public function __call($method, array $parameters = array()) |
||
205 | |||
206 | /** |
||
207 | * {inheritdoc} |
||
208 | */ |
||
209 | public function __get($property) |
||
224 | |||
225 | /** |
||
226 | 4 | * {inheritdoc} |
|
227 | */ |
||
228 | public function __set($property, $value) |
||
234 | } |
||
235 |