|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Remorhaz\JSON\Patch\Query; |
|
5
|
|
|
|
|
6
|
|
|
use Collator; |
|
7
|
|
|
use Remorhaz\JSON\Data\Comparator\EqualValueComparator; |
|
8
|
|
|
use Remorhaz\JSON\Data\Export\ValueDecoder; |
|
9
|
|
|
use Remorhaz\JSON\Data\Export\ValueDecoderInterface; |
|
10
|
|
|
use Remorhaz\JSON\Data\Export\ValueEncoder; |
|
11
|
|
|
use Remorhaz\JSON\Data\Export\ValueEncoderInterface; |
|
12
|
|
|
use Remorhaz\JSON\Data\Value\NodeValueInterface; |
|
13
|
|
|
use Remorhaz\JSON\Patch\Operation\OperationFactory; |
|
14
|
|
|
use Remorhaz\JSON\Patch\Operation\OperationFactoryInterface; |
|
15
|
|
|
use Remorhaz\JSON\Pointer\Processor\Processor as PointerProcessor; |
|
16
|
|
|
use Remorhaz\JSON\Pointer\Query\QueryFactory as PointerQueryFactory; |
|
17
|
|
|
|
|
18
|
|
|
final class QueryFactory implements QueryFactoryInterface |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
private $operationFactory; |
|
22
|
|
|
|
|
23
|
|
|
private $encoder; |
|
24
|
|
|
|
|
25
|
|
|
private $decoder; |
|
26
|
|
|
|
|
27
|
|
|
public static function create(): QueryFactoryInterface |
|
28
|
|
|
{ |
|
29
|
|
|
$decoder = new ValueDecoder; |
|
30
|
|
|
|
|
31
|
|
|
return new self( |
|
32
|
|
|
new OperationFactory( |
|
33
|
|
|
PointerQueryFactory::create(), |
|
34
|
|
|
PointerProcessor::create(), |
|
35
|
|
|
new EqualValueComparator(new Collator('UTF-8')) |
|
36
|
|
|
), |
|
37
|
|
|
new ValueEncoder($decoder), |
|
38
|
|
|
$decoder |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function __construct( |
|
43
|
|
|
OperationFactoryInterface $operationFactory, |
|
44
|
|
|
ValueEncoderInterface $encoder, |
|
45
|
|
|
ValueDecoderInterface $decoder |
|
46
|
|
|
) { |
|
47
|
|
|
$this->operationFactory = $operationFactory; |
|
48
|
|
|
$this->encoder = $encoder; |
|
49
|
|
|
$this->decoder = $decoder; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function createQuery(NodeValueInterface $patch): QueryInterface |
|
53
|
|
|
{ |
|
54
|
|
|
return new LazyQuery($this->operationFactory, $this->encoder, $this->decoder, $patch); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|