LaravelFreelancerNL /
laravel-arangodb
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace LaravelFreelancerNL\Aranguent\Eloquent\Concerns; |
||
| 6 | |||
| 7 | trait HasAttributes |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Determine whether a value is JSON castable for inbound manipulation. |
||
| 11 | * |
||
| 12 | * @param string $key |
||
| 13 | * @return bool |
||
| 14 | */ |
||
| 15 | 44 | protected function isJsonCastable($key) |
|
| 16 | { |
||
| 17 | 44 | return $this->hasCast($key, ['encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object']); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Decode the given JSON back into an array or object. |
||
| 22 | * |
||
| 23 | * @param string $value |
||
| 24 | * @param bool $asObject |
||
| 25 | * @return mixed |
||
| 26 | * |
||
| 27 | * @SuppressWarnings("PHPMD.BooleanArgumentFlag") |
||
| 28 | */ |
||
| 29 | 5 | public function fromJson($value, $asObject = false) |
|
| 30 | { |
||
| 31 | // As data is stored as json in ArangoDB we don't have to decode it here. |
||
| 32 | 5 | if ($asObject) { |
|
| 33 | 1 | return (object) $value; |
|
| 34 | } |
||
| 35 | |||
| 36 | // Recursively cast objects within the value to arrays |
||
| 37 | 4 | return mapObjectToArray($value); |
|
| 38 | } |
||
| 39 | } |
||
| 40 |