-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProcessor.php
32 lines (27 loc) · 932 Bytes
/
Processor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
namespace Remorhaz\JSON\Patch\Processor;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Patch\Query\QueryInterface;
use Remorhaz\JSON\Patch\Result\ResultInterface;
use Remorhaz\JSON\Pointer\Processor\Processor as PointerProcessor;
use Remorhaz\JSON\Pointer\Processor\ProcessorInterface as PointerProcessorInterface;
use Throwable;
class Processor implements ProcessorInterface
{
public static function create(): ProcessorInterface
{
return new self(PointerProcessor::create());
}
public function __construct(
private readonly PointerProcessorInterface $pointerProcessor,
) {
}
public function apply(QueryInterface $query, NodeValueInterface $data): ResultInterface
{
try {
return $query($data, $this->pointerProcessor);
} catch (Throwable $e) {
throw new Exception\PatchNotAppliedException($e);
}
}
}