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