1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Language\AST\Visitor; |
4
|
|
|
|
5
|
|
|
use Digia\GraphQL\Language\AST\Node\NodeInterface; |
6
|
|
|
use Digia\GraphQL\Util\SerializationInterface; |
7
|
|
|
|
8
|
|
|
class KindVisitor extends Visitor |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
protected $enterKinds = []; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
protected $leaveKinds = []; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* KindVisitor constructor. |
23
|
|
|
* @param array $enterKinds |
24
|
|
|
* @param array $leaveKinds |
25
|
|
|
* @param callable|null $enterFunction |
26
|
|
|
* @param callable|null $leaveFunction |
27
|
|
|
*/ |
28
|
|
|
public function __construct( |
29
|
|
|
array $enterKinds, |
30
|
|
|
array $leaveKinds, |
31
|
|
|
?callable $enterFunction = null, |
32
|
|
|
?callable $leaveFunction = null |
33
|
|
|
) { |
34
|
|
|
parent::__construct($enterFunction, $leaveFunction); |
35
|
|
|
|
36
|
|
|
$this->enterKinds = $enterKinds; |
37
|
|
|
$this->leaveKinds = $leaveKinds; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritdoc |
43
|
|
|
*/ |
44
|
|
|
public function enterNode( |
45
|
|
|
NodeInterface $node, |
46
|
|
|
$key = null, |
47
|
|
|
?NodeInterface $parent = null, |
48
|
|
|
array $path = [] |
49
|
|
|
): ?NodeInterface { |
50
|
|
|
if (\in_array($node->getKind(), $this->enterKinds, true)) { |
51
|
|
|
return parent::enterNode($node, $key, $parent, $path); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $node; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @inheritdoc |
59
|
|
|
*/ |
60
|
|
|
public function leaveNode( |
61
|
|
|
NodeInterface $node, |
62
|
|
|
$key = null, |
63
|
|
|
?NodeInterface $parent = null, |
64
|
|
|
array $path = [] |
65
|
|
|
): ?NodeInterface { |
66
|
|
|
if (\in_array($node->getKind(), $this->leaveKinds, true)) { |
67
|
|
|
return parent::leaveNode($node, $key, $parent, $path); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $node; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|