22
33namespace Remorhaz \JSON \Patch ;
44
5- use Remorhaz \JSON \Data \SelectableReaderInterface ;
5+ use Remorhaz \JSON \Data \SelectorInterface ;
66use Remorhaz \JSON \Pointer \Pointer ;
77
88class Patch
99{
1010
11- private $ dataReader ;
11+ private $ dataSelector ;
1212
13- private $ patchReader ;
13+ private $ patchSelector ;
1414
1515 private $ dataPointer ;
1616
1717 private $ patchPointer ;
1818
1919
20- public function __construct (SelectableReaderInterface $ dataReader )
20+ public function __construct (SelectorInterface $ dataSelector )
2121 {
22- $ this ->dataReader = $ dataReader ;
22+ $ this ->dataSelector = $ dataSelector ;
2323 }
2424
2525
26- public function apply (SelectableReaderInterface $ patchReader )
26+ public function apply (SelectorInterface $ patchSelector )
2727 {
2828 $ this
29- ->setPatchReader ( $ patchReader )
30- ->getPatchReader ()
29+ ->setPatchSelector ( $ patchSelector )
30+ ->getPatchSelector ()
3131 ->selectRoot ();
32- if (!$ this ->getPatchReader ()->isArraySelected ()) {
32+ if (!$ this ->getPatchSelector ()->isArray ()) {
3333 throw new \RuntimeException ("Patch must be an array " );
3434 }
3535 $ operationCount = $ this
36- ->getPatchReader ()
36+ ->getPatchSelector ()
3737 ->getElementCount ();
3838 for ($ operationIndex = 0 ; $ operationIndex < $ operationCount ; $ operationIndex ++) {
3939 $ this ->performOperation ($ operationIndex );
@@ -42,16 +42,16 @@ public function apply(SelectableReaderInterface $patchReader)
4242 }
4343
4444
45- protected function getDataReader (): SelectableReaderInterface
45+ protected function getDataSelector (): SelectorInterface
4646 {
47- return $ this ->dataReader ;
47+ return $ this ->dataSelector ;
4848 }
4949
5050
5151 protected function performOperation (int $ index )
5252 {
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 ();
5555 switch ($ operation ) {
5656 case 'add ' :
5757 $ valueReader = $ this ->getPatchPointer ()->read ("/ {$ index }/value " );
@@ -70,19 +70,19 @@ protected function performOperation(int $index)
7070 case 'test ' :
7171 $ expectedValueReader = $ this ->getPatchPointer ()->read ("/ {$ index }/value " );
7272 $ actualValueReader = $ this ->getDataPointer ()->read ($ path );
73- if ($ expectedValueReader ->getData () !== $ actualValueReader ->getData ()) {
73+ if ($ expectedValueReader ->getAsStruct () !== $ actualValueReader ->getAsStruct ()) {
7474 throw new \RuntimeException ("Test operation failed " );
7575 }
7676 break ;
7777
7878 case 'copy ' :
79- $ from = $ this ->getPatchPointer ()->read ("/ {$ index }/from " )->getData ();
79+ $ from = $ this ->getPatchPointer ()->read ("/ {$ index }/from " )->getAsString ();
8080 $ valueReader = $ this ->getDataPointer ()->read ($ from );
8181 $ this ->getDataPointer ()->add ($ path , $ valueReader );
8282 break ;
8383
8484 case 'move ' :
85- $ from = $ this ->getPatchPointer ()->read ("/ {$ index }/from " )->getData ();
85+ $ from = $ this ->getPatchPointer ()->read ("/ {$ index }/from " )->getAsString ();
8686 $ valueReader = $ this ->getDataPointer ()->read ($ from );
8787 $ this
8888 ->getDataPointer ()
@@ -97,26 +97,26 @@ protected function performOperation(int $index)
9797 }
9898
9999
100- protected function setPatchReader ( SelectableReaderInterface $ patchReader )
100+ protected function setPatchSelector ( SelectorInterface $ patchReader )
101101 {
102- $ this ->patchReader = $ patchReader ;
102+ $ this ->patchSelector = $ patchReader ;
103103 return $ this ;
104104 }
105105
106106
107- protected function getPatchReader (): SelectableReaderInterface
107+ protected function getPatchSelector (): SelectorInterface
108108 {
109- if (null === $ this ->patchReader ) {
109+ if (null === $ this ->patchSelector ) {
110110 throw new \LogicException ("Patch reader is not set " );
111111 }
112- return $ this ->patchReader ;
112+ return $ this ->patchSelector ;
113113 }
114114
115115
116116 protected function getPatchPointer (): Pointer
117117 {
118118 if (null === $ this ->patchPointer ) {
119- $ this ->patchPointer = new Pointer ($ this ->getPatchReader ());
119+ $ this ->patchPointer = new Pointer ($ this ->getPatchSelector ());
120120 }
121121 return $ this ->patchPointer ;
122122 }
@@ -125,7 +125,7 @@ protected function getPatchPointer(): Pointer
125125 protected function getDataPointer (): Pointer
126126 {
127127 if (null === $ this ->dataPointer ) {
128- $ this ->dataPointer = new Pointer ($ this ->getDataReader ());
128+ $ this ->dataPointer = new Pointer ($ this ->getDataSelector ());
129129 }
130130 return $ this ->dataPointer ;
131131 }
0 commit comments