1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Smoren\NestedAccessor\Components; |
4
|
|
|
|
5
|
|
|
use Smoren\NestedAccessor\Exceptions\NestedAccessorException; |
6
|
|
|
use Smoren\NestedAccessor\Interfaces\SilentNestedAccessorInterface; |
7
|
|
|
|
8
|
|
|
class SilentNestedAccessor implements SilentNestedAccessorInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var NestedAccessor |
12
|
|
|
*/ |
13
|
|
|
protected NestedAccessor $nestedAccessor; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* ArrayNestedAccessor constructor. |
17
|
|
|
* @param array<scalar, mixed>|object $source |
18
|
|
|
* @param non-empty-string $pathDelimiter |
|
|
|
|
19
|
|
|
* @throws NestedAccessorException |
20
|
|
|
*/ |
21
|
|
|
public function __construct(&$source, string $pathDelimiter = '.') |
22
|
|
|
{ |
23
|
|
|
$this->nestedAccessor = new NestedAccessor($source, $pathDelimiter); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritDoc} |
28
|
|
|
*/ |
29
|
|
|
public function get($path = null) |
30
|
|
|
{ |
31
|
|
|
return $this->nestedAccessor->get($path, false); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritDoc} |
36
|
|
|
*/ |
37
|
|
|
public function set($path, $value): self |
38
|
|
|
{ |
39
|
|
|
$this->nestedAccessor->set($path, $value, false); |
40
|
|
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritDoc} |
45
|
|
|
*/ |
46
|
|
|
public function append($path, $value): self |
47
|
|
|
{ |
48
|
|
|
$this->nestedAccessor->append($path, $value, false); |
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritDoc} |
54
|
|
|
*/ |
55
|
|
|
public function delete($path): self |
56
|
|
|
{ |
57
|
|
|
$this->nestedAccessor->delete($path, false); |
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritDoc} |
63
|
|
|
*/ |
64
|
|
|
public function exist($path): bool |
65
|
|
|
{ |
66
|
|
|
return $this->nestedAccessor->exist($path); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
*/ |
72
|
|
|
public function isset($path): bool |
73
|
|
|
{ |
74
|
|
|
return $this->nestedAccessor->isset($path); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|