From b305045b13b90c2f8bfb02475c9da9a71e49b915 Mon Sep 17 00:00:00 2001 From: Michael Aerni Date: Mon, 3 Jun 2024 13:32:12 +0200 Subject: [PATCH 1/4] Add ValueSynthesizer --- config/config.php | 1 + src/Synthesizers/ValueSynthesizer.php | 46 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/Synthesizers/ValueSynthesizer.php diff --git a/config/config.php b/config/config.php index de89c4a..66df55a 100644 --- a/config/config.php +++ b/config/config.php @@ -27,6 +27,7 @@ 'classes' => [ \Jonassiewertsen\Livewire\Synthesizers\EntryCollectionSynthesizer::class, \Jonassiewertsen\Livewire\Synthesizers\EntrySynthesizer::class, + \Jonassiewertsen\Livewire\Synthesizers\ValueSynthesizer::class, ], ], diff --git a/src/Synthesizers/ValueSynthesizer.php b/src/Synthesizers/ValueSynthesizer.php new file mode 100644 index 0000000..d99dd9f --- /dev/null +++ b/src/Synthesizers/ValueSynthesizer.php @@ -0,0 +1,46 @@ + $value->raw, + 'handle' => $value->handle, + 'fieldtype' => $value->fieldtype, + 'augmentable' => $value->augmentable, + 'shallow' => $value->shallow, + ]; + + foreach ($data as $key => $child) { + $data[$key] = $dehydrateChild($key, $child); + } + + return [$data, []]; + } + + public function hydrate($value, $meta, $hydrateChild) + { + foreach ($value as $key => $child) { + $value[$key] = $hydrateChild($key, $child); + } + + return new Value(...$value); + } +} From 0d6261c0021e4ebc6e6bf079dbea39c74235e7fc Mon Sep 17 00:00:00 2001 From: Michael Aerni Date: Mon, 3 Jun 2024 14:24:37 +0200 Subject: [PATCH 2/4] Add FieldtypeSynthesizer --- config/config.php | 1 + src/Synthesizers/FieldtypeSynthesizer.php | 41 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/Synthesizers/FieldtypeSynthesizer.php diff --git a/config/config.php b/config/config.php index 66df55a..26c28ba 100644 --- a/config/config.php +++ b/config/config.php @@ -27,6 +27,7 @@ 'classes' => [ \Jonassiewertsen\Livewire\Synthesizers\EntryCollectionSynthesizer::class, \Jonassiewertsen\Livewire\Synthesizers\EntrySynthesizer::class, + \Jonassiewertsen\Livewire\Synthesizers\FieldtypeSynthesizer::class, \Jonassiewertsen\Livewire\Synthesizers\ValueSynthesizer::class, ], ], diff --git a/src/Synthesizers/FieldtypeSynthesizer.php b/src/Synthesizers/FieldtypeSynthesizer.php new file mode 100644 index 0000000..a391e53 --- /dev/null +++ b/src/Synthesizers/FieldtypeSynthesizer.php @@ -0,0 +1,41 @@ + $target->field(), + ]; + + foreach ($data as $key => $child) { + $data[$key] = $dehydrateChild($key, $child); + } + + return [ + $data, + ['class' => get_class($target)], + ]; + } + + public function hydrate($value, $meta, $hydrateChild) + { + foreach ($value as $key => $child) { + $value[$key] = $hydrateChild($key, $child); + } + + return app($meta['class'])->setField($value['field']); + } +} From f8250ad703cf38876005ab033f501f5b3970f0c5 Mon Sep 17 00:00:00 2001 From: Michael Aerni Date: Mon, 3 Jun 2024 14:24:52 +0200 Subject: [PATCH 3/4] Add FieldSynthesizer --- config/config.php | 1 + src/Synthesizers/FieldSynthesizer.php | 39 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/Synthesizers/FieldSynthesizer.php diff --git a/config/config.php b/config/config.php index 26c28ba..f0d5268 100644 --- a/config/config.php +++ b/config/config.php @@ -27,6 +27,7 @@ 'classes' => [ \Jonassiewertsen\Livewire\Synthesizers\EntryCollectionSynthesizer::class, \Jonassiewertsen\Livewire\Synthesizers\EntrySynthesizer::class, + \Jonassiewertsen\Livewire\Synthesizers\FieldSynthesizer::class, \Jonassiewertsen\Livewire\Synthesizers\FieldtypeSynthesizer::class, \Jonassiewertsen\Livewire\Synthesizers\ValueSynthesizer::class, ], diff --git a/src/Synthesizers/FieldSynthesizer.php b/src/Synthesizers/FieldSynthesizer.php new file mode 100644 index 0000000..da2a85f --- /dev/null +++ b/src/Synthesizers/FieldSynthesizer.php @@ -0,0 +1,39 @@ + $target->handle(), + 'config' => $target->config(), + ]; + + foreach ($data as $key => $child) { + $data[$key] = $dehydrateChild($key, $child); + } + + return [$data, []]; + } + + public function hydrate($value, $meta, $hydrateChild) + { + foreach ($value as $key => $child) { + $value[$key] = $hydrateChild($key, $child); + } + + return new Field(...$value); + } +} From e37e63c62ad48214e0e90c678ecc71fbd53cc9c9 Mon Sep 17 00:00:00 2001 From: aerni Date: Mon, 3 Jun 2024 12:28:54 +0000 Subject: [PATCH 4/4] [auto commit] Linting --- src/Synthesizers/ValueSynthesizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Synthesizers/ValueSynthesizer.php b/src/Synthesizers/ValueSynthesizer.php index d99dd9f..1eb5792 100644 --- a/src/Synthesizers/ValueSynthesizer.php +++ b/src/Synthesizers/ValueSynthesizer.php @@ -25,7 +25,7 @@ public function dehydrate($target, $dehydrateChild) 'handle' => $value->handle, 'fieldtype' => $value->fieldtype, 'augmentable' => $value->augmentable, - 'shallow' => $value->shallow, + 'shallow' => $value->shallow, ]; foreach ($data as $key => $child) {