1 | <?php |
||
15 | class Fluent implements ArrayAccess, JsonSerializable |
||
16 | { |
||
17 | /** |
||
18 | * All of the attributes set on the container. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $attributes = []; |
||
23 | |||
24 | /** |
||
25 | * Create a new fluent container instance. |
||
26 | * |
||
27 | * @param array|object $attributes |
||
28 | * @return void|mixed |
||
|
|||
29 | */ |
||
30 | public function __construct($attributes = []) |
||
36 | |||
37 | /** |
||
38 | * Get an attribute from the container. |
||
39 | * |
||
40 | * @param string $key |
||
41 | * @param mixed $default |
||
42 | * @return mixed |
||
43 | */ |
||
44 | public function get($key, $default = null) |
||
53 | |||
54 | /** |
||
55 | * Get the attributes from the container. |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | public function getAttributes() |
||
63 | |||
64 | /** |
||
65 | * Convert the Fluent instance to an array. |
||
66 | * |
||
67 | * @return array |
||
68 | */ |
||
69 | public function toArray() |
||
73 | |||
74 | /** |
||
75 | * Convert the object into something JSON serializable. |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | public function jsonSerialize() |
||
83 | |||
84 | /** |
||
85 | * Convert the Fluent instance to JSON. |
||
86 | * |
||
87 | * @param int $options |
||
88 | * @return string |
||
89 | */ |
||
90 | public function toJson($options = 0) |
||
94 | |||
95 | /** |
||
96 | * Determine if the given offset exists. |
||
97 | * |
||
98 | * @param string $offset |
||
99 | * @return bool |
||
100 | */ |
||
101 | public function offsetExists($offset) |
||
105 | |||
106 | /** |
||
107 | * Get the value for a given offset. |
||
108 | * |
||
109 | * @param string $offset |
||
110 | * @return mixed |
||
111 | */ |
||
112 | public function offsetGet($offset) |
||
116 | |||
117 | /** |
||
118 | * Set the value at the given offset. |
||
119 | * |
||
120 | * @param string $offset |
||
121 | * @param mixed $value |
||
122 | * @return void |
||
123 | */ |
||
124 | public function offsetSet($offset, $value) |
||
128 | |||
129 | /** |
||
130 | * Unset the value at the given offset. |
||
131 | * |
||
132 | * @param string $offset |
||
133 | * @return void |
||
134 | */ |
||
135 | public function offsetUnset($offset) |
||
139 | |||
140 | /** |
||
141 | * Handle dynamic calls to the container to set attributes. |
||
142 | * |
||
143 | * @param string $method |
||
144 | * @param array $parameters |
||
145 | * @return $this |
||
146 | */ |
||
147 | public function __call($method, $parameters) |
||
153 | |||
154 | /** |
||
155 | * Dynamically retrieve the value of an attribute. |
||
156 | * |
||
157 | * @param string $key |
||
158 | * @return mixed |
||
159 | */ |
||
160 | public function __get($key) |
||
164 | |||
165 | /** |
||
166 | * Dynamically set the value of an attribute. |
||
167 | * |
||
168 | * @param string $key |
||
169 | * @param mixed $value |
||
170 | * @return void |
||
171 | */ |
||
172 | public function __set($key, $value) |
||
176 | |||
177 | /** |
||
178 | * Dynamically check if an attribute is set. |
||
179 | * |
||
180 | * @param string $key |
||
181 | * @return bool |
||
182 | */ |
||
183 | public function __isset($key) |
||
187 | |||
188 | /** |
||
189 | * Dynamically unset an attribute. |
||
190 | * |
||
191 | * @param string $key |
||
192 | * @return void |
||
193 | */ |
||
194 | public function __unset($key) |
||
198 | } |
||
199 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.