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 accessors to append during array transformation. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $appends = []; |
||
36 | |||
37 | /** |
||
38 | * Array related models indexed by the relation names. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | public $related = []; |
||
43 | |||
44 | /** |
||
45 | * Set method for ArrayIterator. |
||
46 | * |
||
47 | * @param $offset |
||
48 | * @param $value |
||
49 | * |
||
50 | * @return void |
||
51 | */ |
||
52 | public function offsetSet($offset, $value) |
||
60 | |||
61 | /** |
||
62 | * Exists method for ArrayIterator. |
||
63 | * |
||
64 | * @param $offset |
||
65 | * |
||
66 | * @return bool |
||
67 | */ |
||
68 | public function offsetExists($offset) |
||
72 | |||
73 | /** |
||
74 | * Unset method for ArrayIterator. |
||
75 | * |
||
76 | * @param $offset |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | public function offsetUnset($offset) |
||
84 | |||
85 | /** |
||
86 | * Get method for ArrayIterator. |
||
87 | * |
||
88 | * @param $offset |
||
89 | * |
||
90 | * @return mixed |
||
91 | */ |
||
92 | public function offsetGet($offset) |
||
99 | |||
100 | /** |
||
101 | * Get an iterator for fields. |
||
102 | * |
||
103 | * @return ArrayIterator |
||
104 | */ |
||
105 | public function getIterator() |
||
109 | |||
110 | /** |
||
111 | * Get accessor method name if it exists. |
||
112 | * |
||
113 | * @param string $field |
||
114 | * |
||
115 | * @return string|false |
||
116 | */ |
||
117 | private function getAccessor($field) |
||
123 | |||
124 | /** |
||
125 | * Add value to append. |
||
126 | * |
||
127 | * @param array|string $attributes |
||
128 | * @return $this |
||
129 | */ |
||
130 | public function append($attributes) |
||
138 | |||
139 | /** |
||
140 | * Setter for appends. |
||
141 | * |
||
142 | * @param array $appends |
||
143 | * @return $this |
||
144 | */ |
||
145 | public function setAppends(array $appends) |
||
151 | |||
152 | /** |
||
153 | * Cast model to array. |
||
154 | * |
||
155 | * @return array |
||
156 | */ |
||
157 | public function toArray() |
||
185 | |||
186 | /** |
||
187 | * Convert model to json. |
||
188 | * |
||
189 | * @param int $options |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | public function toJson($options = 0) |
||
197 | } |
||
198 |