-
Notifications
You must be signed in to change notification settings - Fork 15
Add Cast for JSON #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add Cast for JSON #265
Changes from 5 commits
dbc6393
b3fe074
5fe33e4
f671a3d
be6792c
bd72498
c487dd0
b6ddc9b
ec6efc8
a8de8cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| namespace App\Casts; | ||
|
|
||
| use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
| use JsonSerializable; | ||
|
|
||
| /** | ||
| * @implements CastsAttributes<array|null, array> | ||
| */ | ||
| class SpannerJson implements CastsAttributes | ||
| { | ||
| public function get($model, $key, $value, $attributes): array|null | ||
| { | ||
| if ($value === null) { | ||
| return null; | ||
| } | ||
|
|
||
| if(is_array($value)) { | ||
| return $value; | ||
| } | ||
|
|
||
| if(!is_string($value)) { | ||
| throw new \InvalidArgumentException('The given value must be an array, string or null.'); | ||
| } | ||
|
|
||
| return json_decode($value, true); | ||
| } | ||
|
|
||
| public function set($model, $key, $value, $attributes): array | ||
| { | ||
| if (!is_array($value) && !$value instanceof JsonSerializable && $value !== null && !is_string($value)) { | ||
| throw new \InvalidArgumentException('The given value must be an array, JsonSerializable, string or null.'); | ||
| } | ||
|
|
||
| return [$key => new SpannerJsonType($value)]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ Verification inconclusiveMissing import for SpannerJsonType class. The +use Colopl\Spanner\Query\Grammar\SpannerJsonType;
namespace Colopl\Spanner\Casts;Please verify the correct namespace and path for the 🏁 Script executed: #!/bin/bash
# Search for the SpannerJsonType class in the codebase
echo "Searching for SpannerJsonType class..."
rg -l "class SpannerJsonType" --type phpLength of output: 129 Verify Missing Import for SpannerJsonType The code instantiates a new
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.