1 | <?php |
||
12 | abstract class ArrayableModel implements ArrayAccess, Arrayable, Jsonable, IteratorAggregate |
||
13 | { |
||
14 | use HidesAttributes; |
||
15 | |||
16 | /** |
||
17 | * ID of the model. |
||
18 | * |
||
19 | * @var null|int |
||
20 | */ |
||
21 | public $id; |
||
22 | |||
23 | /** |
||
24 | * Array of model fields. |
||
25 | * |
||
26 | * @var null|array |
||
27 | */ |
||
28 | public $fields; |
||
29 | |||
30 | /** |
||
31 | * Array of original model fields. |
||
32 | * |
||
33 | * @var null|array |
||
34 | */ |
||
35 | protected $original; |
||
36 | |||
37 | /** |
||
38 | * Array of accessors to append during array transformation. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $appends = []; |
||
43 | |||
44 | /** |
||
45 | * Array of language fields with auto accessors. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $languageAccessors = []; |
||
50 | |||
51 | /** |
||
52 | * Array related models indexed by the relation names. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | public $related = []; |
||
57 | |||
58 | /** |
||
59 | * Set method for ArrayIterator. |
||
60 | * |
||
61 | * @param $offset |
||
62 | * @param $value |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | public function offsetSet($offset, $value) |
||
74 | |||
75 | /** |
||
76 | * Exists method for ArrayIterator. |
||
77 | * |
||
78 | * @param $offset |
||
79 | * |
||
80 | * @return bool |
||
81 | */ |
||
82 | public function offsetExists($offset) |
||
87 | |||
88 | /** |
||
89 | * Unset method for ArrayIterator. |
||
90 | * |
||
91 | * @param $offset |
||
92 | * |
||
93 | * @return void |
||
94 | */ |
||
95 | public function offsetUnset($offset) |
||
99 | |||
100 | /** |
||
101 | * Get method for ArrayIterator. |
||
102 | * |
||
103 | * @param $offset |
||
104 | * |
||
105 | * @return mixed |
||
106 | */ |
||
107 | public function offsetGet($offset) |
||
122 | |||
123 | /** |
||
124 | * Get an iterator for fields. |
||
125 | * |
||
126 | * @return ArrayIterator |
||
127 | */ |
||
128 | public function getIterator() |
||
132 | |||
133 | /** |
||
134 | * Get accessor method name if it exists. |
||
135 | * |
||
136 | * @param string $field |
||
137 | * |
||
138 | * @return string|false |
||
139 | */ |
||
140 | private function getAccessor($field) |
||
146 | |||
147 | /** |
||
148 | * Get accessor for language field method name if it exists. |
||
149 | * |
||
150 | * @param string $field |
||
151 | * |
||
152 | * @return string|false |
||
153 | */ |
||
154 | private function getAccessorForLanguageField($field) |
||
160 | |||
161 | /** |
||
162 | * Add value to append. |
||
163 | * |
||
164 | * @param array|string $attributes |
||
165 | * @return $this |
||
166 | */ |
||
167 | public function append($attributes) |
||
175 | |||
176 | /** |
||
177 | * Setter for appends. |
||
178 | * |
||
179 | * @param array $appends |
||
180 | * @return $this |
||
181 | */ |
||
182 | public function setAppends(array $appends) |
||
188 | |||
189 | /** |
||
190 | * Cast model to array. |
||
191 | * |
||
192 | * @return array |
||
193 | */ |
||
194 | public function toArray() |
||
222 | |||
223 | /** |
||
224 | * Convert model to json. |
||
225 | * |
||
226 | * @param int $options |
||
227 | * |
||
228 | * @return string |
||
229 | */ |
||
230 | public function toJson($options = 0) |
||
234 | } |
||
235 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: