/
ArraySynth.php
43 lines (33 loc) · 1.08 KB
/
ArraySynth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Livewire\Mechanisms\HandleComponents\Synthesizers;
class ArraySynth extends Synth {
public static $key = 'arr';
static function match($target) {
return is_array($target);
}
function dehydrate($target, $dehydrateChild) {
foreach ($target as $key => $child) {
$target[$key] = $dehydrateChild($key, $child);
}
return [$target, []];
}
function hydrate($value, $meta, $hydrateChild) {
// If we are "hydrating" a value about to be used in an update,
// Let's make sure it's actually an array before try to set it.
// This is most common in the case of "__rm__" values, but also
// applies to any non-array value...
if (! is_array($value)) {
return $value;
}
foreach ($value as $key => $child) {
$value[$key] = $hydrateChild($key, $child);
}
return $value;
}
function set(&$target, $key, $value) {
$target[$key] = $value;
}
function unset(&$target, $key) {
unset($target[$key]);
}
}