|
4 | 4 |
|
5 | 5 | namespace MatanYadaev\EloquentSpatial\Objects; |
6 | 6 |
|
| 7 | +use ArrayAccess; |
7 | 8 | use Illuminate\Database\Query\Expression; |
8 | 9 | use Illuminate\Support\Collection; |
9 | 10 | use Illuminate\Support\Facades\DB; |
10 | 11 | use Illuminate\Support\Str; |
11 | 12 | use InvalidArgumentException; |
12 | 13 |
|
13 | | -class GeometryCollection extends Geometry |
| 14 | +class GeometryCollection extends Geometry implements ArrayAccess |
14 | 15 | { |
15 | 16 | /** @var Collection<Geometry> */ |
16 | 17 | protected Collection $geometries; |
@@ -71,11 +72,11 @@ public function toArray(): array |
71 | 72 | } |
72 | 73 |
|
73 | 74 | /** |
74 | | - * @return array<Geometry> |
| 75 | + * @return Collection<Geometry> |
75 | 76 | */ |
76 | | - public function getGeometries(): array |
| 77 | + public function getGeometries(): Collection |
77 | 78 | { |
78 | | - return $this->geometries->all(); |
| 79 | + return $this->geometries->collect(); |
79 | 80 | } |
80 | 81 |
|
81 | 82 | /** |
@@ -120,4 +121,41 @@ protected function toCollectionWkt(): Expression |
120 | 121 |
|
121 | 122 | return DB::raw($wkb); |
122 | 123 | } |
| 124 | + |
| 125 | + /** |
| 126 | + * @param mixed $offset |
| 127 | + * @return bool |
| 128 | + */ |
| 129 | + public function offsetExists($offset): bool |
| 130 | + { |
| 131 | + return isset($this->geometries[$offset]); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * @param mixed $offset |
| 136 | + * @return Geometry |
| 137 | + */ |
| 138 | + public function offsetGet($offset): Geometry |
| 139 | + { |
| 140 | + return $this->geometries[$offset]; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * @param mixed $offset |
| 145 | + * @param Geometry $geometry |
| 146 | + */ |
| 147 | + public function offsetSet($offset, $geometry): void |
| 148 | + { |
| 149 | + $this->geometries[$offset] = $geometry; |
| 150 | + $this->validateGeometriesType(); |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * @param mixed $offset |
| 155 | + */ |
| 156 | + public function offsetUnset($offset): void |
| 157 | + { |
| 158 | + $this->geometries->splice($offset, 1); |
| 159 | + $this->validateGeometriesCount(); |
| 160 | + } |
123 | 161 | } |
0 commit comments