1 | <?php |
||
17 | class FieldCollection extends \Illuminate\Support\Collection |
||
18 | { |
||
19 | /** |
||
20 | * @var int The max items this collection can hold |
||
21 | */ |
||
22 | protected $maxItems = 1; |
||
23 | |||
24 | /** |
||
25 | * @var array The Collection configuration |
||
26 | */ |
||
27 | protected $configuration = []; |
||
28 | |||
29 | /** |
||
30 | * @var string The type of this collection |
||
31 | */ |
||
32 | protected $type; |
||
33 | |||
34 | /** |
||
35 | * @var array An array of fields that were deleted |
||
36 | */ |
||
37 | protected $deleted = []; |
||
38 | |||
39 | /** |
||
40 | * Initialize a collection with the configuration |
||
41 | * |
||
42 | * @param array $configuration |
||
43 | * @throws InvalidFieldTypeException |
||
44 | * @return static |
||
45 | */ |
||
46 | 159 | public static function initField($configuration = []) |
|
62 | |||
63 | /** |
||
64 | * Validate input of OffsetSet |
||
65 | * |
||
66 | * @param $key |
||
67 | * @param $value |
||
68 | * @throws ItemCountException |
||
69 | * @throws NullValueException |
||
70 | */ |
||
71 | 129 | protected function validateSet($key, $value) |
|
82 | |||
83 | /** |
||
84 | * Get a field from a value |
||
85 | * |
||
86 | * @param Field|mixed $value |
||
87 | * @return Field |
||
88 | */ |
||
89 | 126 | protected function getFieldInstance($value) |
|
100 | |||
101 | /** |
||
102 | * Set the item at a given offset. |
||
103 | * |
||
104 | * @param mixed $key |
||
105 | * @param mixed $value |
||
106 | * @return void |
||
107 | */ |
||
108 | 129 | public function offsetSet($key, $value) |
|
130 | |||
131 | /** |
||
132 | * Get an item at a given offset. |
||
133 | * |
||
134 | * @param mixed $key |
||
135 | * @return mixed |
||
136 | */ |
||
137 | 9 | public function offsetGet($key) |
|
141 | |||
142 | /** |
||
143 | * Unset the item at a given offset. |
||
144 | * |
||
145 | * @param string $key |
||
146 | * @return void |
||
147 | */ |
||
148 | 33 | public function offsetUnset($key) |
|
155 | |||
156 | /** |
||
157 | * Get all deleted fields |
||
158 | * |
||
159 | * @return Collection |
||
160 | */ |
||
161 | 63 | public function deleted() |
|
165 | |||
166 | /** |
||
167 | * Mark the content as current and saved |
||
168 | */ |
||
169 | 60 | public function syncOriginal() |
|
173 | |||
174 | /** |
||
175 | * Remove all items in this collection |
||
176 | * |
||
177 | * @return void |
||
178 | */ |
||
179 | 28 | public function clear() |
|
187 | |||
188 | /** |
||
189 | * Get the number of items possible in this collection. |
||
190 | * |
||
191 | * @return int |
||
192 | */ |
||
193 | 138 | public function getMaxItems() |
|
197 | |||
198 | /** |
||
199 | * As we use a field collection even if we have only one value, we use it that way. |
||
200 | * |
||
201 | * @return array|mixed|null |
||
202 | */ |
||
203 | 57 | public function toArray() |
|
215 | |||
216 | /** |
||
217 | * Convert the collection to its string representation. |
||
218 | * |
||
219 | * @return string |
||
220 | */ |
||
221 | 3 | public function __toString() |
|
229 | } |
||
230 |