-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathJSONPathToken.php
More file actions
45 lines (38 loc) · 1.21 KB
/
JSONPathToken.php
File metadata and controls
45 lines (38 loc) · 1.21 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* JSONPath implementation for PHP.
*
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
declare(strict_types=1);
namespace Flow\JSONPath;
use Flow\JSONPath\Filters\AbstractFilter;
use Flow\JSONPath\Filters\IndexesFilter;
use Flow\JSONPath\Filters\IndexFilter;
use Flow\JSONPath\Filters\QueryMatchFilter;
use Flow\JSONPath\Filters\QueryResultFilter;
use Flow\JSONPath\Filters\RecursiveFilter;
use Flow\JSONPath\Filters\SliceFilter;
readonly class JSONPathToken
{
public function __construct(
public TokenType $type,
public mixed $value,
public bool $quoted = false,
public bool $shorthand = false,
) {
// ...
}
public function buildFilter(int $options): AbstractFilter
{
$filterClass = match ($this->type) {
TokenType::Index => IndexFilter::class,
TokenType::Indexes => IndexesFilter::class,
TokenType::QueryMatch => QueryMatchFilter::class,
TokenType::QueryResult => QueryResultFilter::class,
TokenType::Recursive => RecursiveFilter::class,
TokenType::Slice => SliceFilter::class,
};
return new $filterClass($this, $options);
}
}