1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Remorhaz\JSON\Pointer\Query; |
5
|
|
|
|
6
|
|
|
use Remorhaz\JSON\Data\Value\NodeValueInterface; |
7
|
|
|
use Remorhaz\JSON\Pointer\Locator\ReferenceInterface; |
8
|
|
|
|
9
|
|
|
final class QueryResult implements QueryResultInterface |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
private $source; |
13
|
|
|
|
14
|
|
|
private $selection; |
15
|
|
|
|
16
|
|
|
private $parent; |
17
|
|
|
|
18
|
|
|
private $lastReference; |
19
|
|
|
|
20
|
13 |
|
public function __construct( |
21
|
|
|
string $source, |
22
|
|
|
?NodeValueInterface $selection = null, |
23
|
|
|
?NodeValueInterface $parent = null, |
24
|
|
|
?ReferenceInterface $lastReference = null |
25
|
|
|
) { |
26
|
13 |
|
$this->source = $source; |
27
|
13 |
|
$this->selection = $selection; |
28
|
13 |
|
$this->parent = $parent; |
29
|
13 |
|
$this->lastReference = $lastReference; |
30
|
13 |
|
} |
31
|
|
|
|
32
|
1 |
|
public function getSource(): string |
33
|
|
|
{ |
34
|
1 |
|
return $this->source; |
35
|
|
|
} |
36
|
|
|
|
37
|
2 |
|
public function getSelection(): NodeValueInterface |
38
|
|
|
{ |
39
|
2 |
|
if (isset($this->selection)) { |
40
|
1 |
|
return $this->selection; |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
throw new Exception\SelectionNotFoundException($this->source); |
44
|
|
|
} |
45
|
|
|
|
46
|
2 |
|
public function hasSelection(): bool |
47
|
|
|
{ |
48
|
2 |
|
return isset($this->selection); |
49
|
|
|
} |
50
|
|
|
|
51
|
2 |
|
public function getParent(): NodeValueInterface |
52
|
|
|
{ |
53
|
2 |
|
if (isset($this->parent)) { |
54
|
1 |
|
return $this->parent; |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
throw new Exception\ParentNotFoundException($this->source); |
58
|
|
|
} |
59
|
|
|
|
60
|
2 |
|
public function hasParent(): bool |
61
|
|
|
{ |
62
|
2 |
|
return isset($this->parent); |
63
|
|
|
} |
64
|
|
|
|
65
|
2 |
|
public function getLastReference(): ReferenceInterface |
66
|
|
|
{ |
67
|
2 |
|
if (isset($this->lastReference)) { |
68
|
1 |
|
return $this->lastReference; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
throw new Exception\LastReferenceNotFoundException($this->source); |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
public function hasLastReference(): bool |
75
|
|
|
{ |
76
|
2 |
|
return isset($this->lastReference); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|