generated from glhd/laravel-package-template
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add synthesizer for Livewire * Convert to string instead of an integer * Change namespace and add generic synth * Code style --------- Co-authored-by: Chris Morrell <[email protected]>
- Loading branch information
1 parent
dbe3b4a
commit 7380ab2
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Glhd\Bits\Support\Livewire; | ||
|
||
use Glhd\Bits\Bits; | ||
use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth; | ||
|
||
class BitsSynth extends Synth | ||
{ | ||
public static string $key = 'bits'; | ||
|
||
public static function match($target) | ||
{ | ||
return $target instanceof Bits; | ||
} | ||
|
||
/** @var Bits $target */ | ||
public function dehydrate($target) | ||
{ | ||
return [$target->jsonSerialize(), ['class' => $target::class]]; | ||
} | ||
|
||
/** | ||
* @param string $value | ||
* @param array{ class: class-string<Bits> } $meta | ||
*/ | ||
public function hydrate($value, $meta) | ||
{ | ||
return $meta['class']::fromId($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Glhd\Bits\Support\Livewire; | ||
|
||
use Glhd\Bits\Snowflake; | ||
use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth; | ||
|
||
class SnowflakeSynth extends Synth | ||
{ | ||
public static string $key = 'snowflake'; | ||
|
||
public static function match($target) | ||
{ | ||
return $target instanceof Snowflake; | ||
} | ||
|
||
/** @var Snowflake $target */ | ||
public function dehydrate($target) | ||
{ | ||
return [$target->jsonSerialize(), []]; | ||
} | ||
|
||
public function hydrate($value) | ||
{ | ||
return Snowflake::fromId($value); | ||
} | ||
} |