2
2
3
3
namespace Remorhaz \JSON \Patch ;
4
4
5
- use Remorhaz \JSON \Data \SelectableReaderInterface ;
5
+ use Remorhaz \JSON \Data \SelectorInterface ;
6
6
use Remorhaz \JSON \Pointer \Pointer ;
7
7
8
8
class Patch
9
9
{
10
10
11
- private $ dataReader ;
11
+ private $ dataSelector ;
12
12
13
- private $ patchReader ;
13
+ private $ patchSelector ;
14
14
15
15
private $ dataPointer ;
16
16
17
17
private $ patchPointer ;
18
18
19
19
20
- public function __construct (SelectableReaderInterface $ dataReader )
20
+ public function __construct (SelectorInterface $ dataSelector )
21
21
{
22
- $ this ->dataReader = $ dataReader ;
22
+ $ this ->dataSelector = $ dataSelector ;
23
23
}
24
24
25
25
26
- public function apply (SelectableReaderInterface $ patchReader )
26
+ public function apply (SelectorInterface $ patchSelector )
27
27
{
28
28
$ this
29
- ->setPatchReader ( $ patchReader )
30
- ->getPatchReader ()
29
+ ->setPatchSelector ( $ patchSelector )
30
+ ->getPatchSelector ()
31
31
->selectRoot ();
32
- if (!$ this ->getPatchReader ()->isArraySelected ()) {
32
+ if (!$ this ->getPatchSelector ()->isArray ()) {
33
33
throw new \RuntimeException ("Patch must be an array " );
34
34
}
35
35
$ operationCount = $ this
36
- ->getPatchReader ()
36
+ ->getPatchSelector ()
37
37
->getElementCount ();
38
38
for ($ operationIndex = 0 ; $ operationIndex < $ operationCount ; $ operationIndex ++) {
39
39
$ this ->performOperation ($ operationIndex );
@@ -42,16 +42,16 @@ public function apply(SelectableReaderInterface $patchReader)
42
42
}
43
43
44
44
45
- protected function getDataReader (): SelectableReaderInterface
45
+ protected function getDataSelector (): SelectorInterface
46
46
{
47
- return $ this ->dataReader ;
47
+ return $ this ->dataSelector ;
48
48
}
49
49
50
50
51
51
protected function performOperation (int $ index )
52
52
{
53
- $ operation = $ this ->getPatchPointer ()->read ("/ {$ index }/op " )->getData ();
54
- $ path = $ this ->getPatchPointer ()->read ("/ {$ index }/path " )->getData ();
53
+ $ operation = $ this ->getPatchPointer ()->read ("/ {$ index }/op " )->getAsString ();
54
+ $ path = $ this ->getPatchPointer ()->read ("/ {$ index }/path " )->getAsString ();
55
55
switch ($ operation ) {
56
56
case 'add ' :
57
57
$ valueReader = $ this ->getPatchPointer ()->read ("/ {$ index }/value " );
@@ -70,19 +70,19 @@ protected function performOperation(int $index)
70
70
case 'test ' :
71
71
$ expectedValueReader = $ this ->getPatchPointer ()->read ("/ {$ index }/value " );
72
72
$ actualValueReader = $ this ->getDataPointer ()->read ($ path );
73
- if ($ expectedValueReader ->getData () !== $ actualValueReader ->getData ()) {
73
+ if ($ expectedValueReader ->getAsStruct () !== $ actualValueReader ->getAsStruct ()) {
74
74
throw new \RuntimeException ("Test operation failed " );
75
75
}
76
76
break ;
77
77
78
78
case 'copy ' :
79
- $ from = $ this ->getPatchPointer ()->read ("/ {$ index }/from " )->getData ();
79
+ $ from = $ this ->getPatchPointer ()->read ("/ {$ index }/from " )->getAsString ();
80
80
$ valueReader = $ this ->getDataPointer ()->read ($ from );
81
81
$ this ->getDataPointer ()->add ($ path , $ valueReader );
82
82
break ;
83
83
84
84
case 'move ' :
85
- $ from = $ this ->getPatchPointer ()->read ("/ {$ index }/from " )->getData ();
85
+ $ from = $ this ->getPatchPointer ()->read ("/ {$ index }/from " )->getAsString ();
86
86
$ valueReader = $ this ->getDataPointer ()->read ($ from );
87
87
$ this
88
88
->getDataPointer ()
@@ -97,26 +97,26 @@ protected function performOperation(int $index)
97
97
}
98
98
99
99
100
- protected function setPatchReader ( SelectableReaderInterface $ patchReader )
100
+ protected function setPatchSelector ( SelectorInterface $ patchReader )
101
101
{
102
- $ this ->patchReader = $ patchReader ;
102
+ $ this ->patchSelector = $ patchReader ;
103
103
return $ this ;
104
104
}
105
105
106
106
107
- protected function getPatchReader (): SelectableReaderInterface
107
+ protected function getPatchSelector (): SelectorInterface
108
108
{
109
- if (null === $ this ->patchReader ) {
109
+ if (null === $ this ->patchSelector ) {
110
110
throw new \LogicException ("Patch reader is not set " );
111
111
}
112
- return $ this ->patchReader ;
112
+ return $ this ->patchSelector ;
113
113
}
114
114
115
115
116
116
protected function getPatchPointer (): Pointer
117
117
{
118
118
if (null === $ this ->patchPointer ) {
119
- $ this ->patchPointer = new Pointer ($ this ->getPatchReader ());
119
+ $ this ->patchPointer = new Pointer ($ this ->getPatchSelector ());
120
120
}
121
121
return $ this ->patchPointer ;
122
122
}
@@ -125,7 +125,7 @@ protected function getPatchPointer(): Pointer
125
125
protected function getDataPointer (): Pointer
126
126
{
127
127
if (null === $ this ->dataPointer ) {
128
- $ this ->dataPointer = new Pointer ($ this ->getDataReader ());
128
+ $ this ->dataPointer = new Pointer ($ this ->getDataSelector ());
129
129
}
130
130
return $ this ->dataPointer ;
131
131
}
0 commit comments