1 | <?php |
||
10 | trait DynamicObjectsTrait |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | protected static $dynamicMethods = array(); |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected static $dynamicProperties = array(); |
||
21 | |||
22 | /** |
||
23 | * Add a dynamic property. |
||
24 | * |
||
25 | * @param string $name |
||
26 | * The property name. |
||
27 | * @param mixed $value |
||
28 | * The property value. |
||
29 | * |
||
30 | */ |
||
31 | 3 | public static function addDynamicProperty($name, $value) |
|
35 | |||
36 | /** |
||
37 | * Add a dynamic method. |
||
38 | * |
||
39 | * @param $name |
||
40 | * The method name. |
||
41 | * @param \Closure $func |
||
42 | * The method. |
||
43 | */ |
||
44 | 3 | public static function addDynamicMethod($name, \Closure $func) |
|
48 | |||
49 | /** |
||
50 | * Check if a dynamic property exists. |
||
51 | * |
||
52 | * @param string $name |
||
53 | * The property name. |
||
54 | * @return bool |
||
55 | * True if the property exists, false otherwise. |
||
56 | */ |
||
57 | 5 | public static function hasDynamicProperty($name) |
|
61 | |||
62 | /** |
||
63 | * Check if a dynamic method exists. |
||
64 | * |
||
65 | * @param string $name |
||
66 | * The property name. |
||
67 | * @return bool |
||
68 | * True if the property exists, false otherwise. |
||
69 | */ |
||
70 | 4 | public static function hasDynamicMethod($name) |
|
74 | |||
75 | /** |
||
76 | * Get a dynamic property. |
||
77 | * |
||
78 | * @param $name |
||
79 | * The property name. |
||
80 | * @return mixed|null |
||
81 | * The property value if it exists, null otherwise. |
||
82 | */ |
||
83 | 1 | public static function getDynamicProperty($name) |
|
88 | |||
89 | /** |
||
90 | * Get a dynamic method. |
||
91 | * |
||
92 | * @param $name |
||
93 | * The method name. |
||
94 | * @return mixed|null |
||
95 | * The method if it exists, null otherwise. |
||
96 | */ |
||
97 | 1 | public static function getDynamicMethod($name) |
|
102 | |||
103 | /** |
||
104 | * Clear dynamic properties. |
||
105 | */ |
||
106 | 1 | public static function clearDynamicProperties() |
|
110 | |||
111 | /** |
||
112 | * Clear dynamic methods. |
||
113 | */ |
||
114 | 1 | public static function clearDynamicMethods() |
|
118 | |||
119 | /** |
||
120 | * Remove a dynamic property. |
||
121 | * |
||
122 | * @param string $name |
||
123 | * The property name. |
||
124 | */ |
||
125 | 1 | public static function removeDynamicProperty($name) |
|
129 | |||
130 | /** |
||
131 | * Remove a dynamic method. |
||
132 | * |
||
133 | * @param string $name |
||
134 | * The method name. |
||
135 | */ |
||
136 | 1 | public static function removeDynamicMethod($name) |
|
140 | |||
141 | /** |
||
142 | * {inheritdoc} |
||
143 | */ |
||
144 | 1 | public function __call($method, $parameters) |
|
155 | |||
156 | /** |
||
157 | * {inheritdoc} |
||
158 | */ |
||
159 | 2 | public function __set($property, $value) |
|
169 | |||
170 | /** |
||
171 | * {inheritdoc} |
||
172 | */ |
||
173 | 1 | public function __get($property) |
|
183 | } |
||
184 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.