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 | 4 | 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 | 6 | 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 | 2 | public static function getDynamicProperty($name) |
|
91 | |||
92 | /** |
||
93 | * Get a dynamic method. |
||
94 | * |
||
95 | * @param $name |
||
96 | * The method name. |
||
97 | * @return mixed|null |
||
98 | * The method if it exists, null otherwise. |
||
99 | */ |
||
100 | 1 | public static function getDynamicMethod($name) |
|
105 | |||
106 | /** |
||
107 | * Clear dynamic properties. |
||
108 | */ |
||
109 | 1 | public static function clearDynamicProperties() |
|
113 | |||
114 | /** |
||
115 | * Clear dynamic methods. |
||
116 | */ |
||
117 | 1 | public static function clearDynamicMethods() |
|
121 | |||
122 | /** |
||
123 | * Remove a dynamic property. |
||
124 | * |
||
125 | * @param string $name |
||
126 | * The property name. |
||
127 | */ |
||
128 | 1 | public static function removeDynamicProperty($name) |
|
132 | |||
133 | /** |
||
134 | * Remove a dynamic method. |
||
135 | * |
||
136 | * @param string $name |
||
137 | * The method name. |
||
138 | */ |
||
139 | 1 | public static function removeDynamicMethod($name) |
|
143 | |||
144 | /** |
||
145 | * {inheritdoc} |
||
146 | */ |
||
147 | 1 | public function __call($method, array $parameters = array()) |
|
156 | |||
157 | /** |
||
158 | * {inheritdoc} |
||
159 | */ |
||
160 | 3 | public function __set($property, $value) |
|
166 | |||
167 | /** |
||
168 | * {inheritdoc} |
||
169 | */ |
||
170 | 2 | public function __get($property) |
|
185 | } |
||
186 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.