ArrayObject.php
1 month ago
AsArrayObject.php
1 month ago
AsCollection.php
1 month ago
AsEncryptedArrayObject.php
1 month ago
AsEncryptedCollection.php
1 month ago
AsEnumArrayObject.php
1 month ago
AsEnumCollection.php
1 month ago
AsStringable.php
1 month ago
Attribute.php
1 month ago
AsArrayObject.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWPSCOPED\Illuminate\Database\Eloquent\Casts; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Contracts\Database\Eloquent\Castable; |
| 6 | use IAWPSCOPED\Illuminate\Contracts\Database\Eloquent\CastsAttributes; |
| 7 | /** @internal */ |
| 8 | class AsArrayObject implements Castable |
| 9 | { |
| 10 | /** |
| 11 | * Get the caster class to use when casting from / to this cast target. |
| 12 | * |
| 13 | * @param array $arguments |
| 14 | * @return CastsAttributes<ArrayObject<array-key, mixed>, iterable> |
| 15 | */ |
| 16 | public static function castUsing(array $arguments) |
| 17 | { |
| 18 | return new class implements CastsAttributes |
| 19 | { |
| 20 | public function get($model, $key, $value, $attributes) |
| 21 | { |
| 22 | if (!isset($attributes[$key])) { |
| 23 | return; |
| 24 | } |
| 25 | $data = \json_decode($attributes[$key], \true); |
| 26 | return \is_array($data) ? new ArrayObject($data) : null; |
| 27 | } |
| 28 | public function set($model, $key, $value, $attributes) |
| 29 | { |
| 30 | return [$key => \json_encode($value)]; |
| 31 | } |
| 32 | public function serialize($model, string $key, $value, array $attributes) |
| 33 | { |
| 34 | return $value->getArrayCopy(); |
| 35 | } |
| 36 | }; |
| 37 | } |
| 38 | } |
| 39 |