1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Schema\Extension; |
4
|
|
|
|
5
|
|
|
use Digia\GraphQL\Language\Node\DirectiveDefinitionNode; |
6
|
|
|
use Digia\GraphQL\Language\Node\DocumentNode; |
7
|
|
|
use Digia\GraphQL\Language\Node\InterfaceTypeExtensionNode; |
8
|
|
|
use Digia\GraphQL\Language\Node\ObjectTypeExtensionNode; |
9
|
|
|
use Digia\GraphQL\Language\Node\TypeDefinitionNodeInterface; |
10
|
|
|
use Digia\GraphQL\Schema\SchemaInterface; |
11
|
|
|
|
12
|
|
|
class ExtensionInfo |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var SchemaInterface |
16
|
|
|
*/ |
17
|
|
|
protected $schema; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var DocumentNode |
21
|
|
|
*/ |
22
|
|
|
protected $document; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var TypeDefinitionNodeInterface[] |
26
|
|
|
*/ |
27
|
|
|
protected $typeDefinitionMap; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var InterfaceTypeExtensionNode[][]|ObjectTypeExtensionNode[][] |
31
|
|
|
*/ |
32
|
|
|
protected $typeExtensionsMap; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var DirectiveDefinitionNode[] |
36
|
|
|
*/ |
37
|
|
|
protected $directiveDefinitions; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* ExtensionInfo constructor. |
41
|
|
|
* @param SchemaInterface $schema |
42
|
|
|
* @param DocumentNode $document |
43
|
|
|
* @param TypeDefinitionNodeInterface[] $typeDefinitionMap |
44
|
|
|
* @param InterfaceTypeExtensionNode[][]|ObjectTypeExtensionNode[][] $typeExtensionsMap |
45
|
|
|
* @param DirectiveDefinitionNode[] $directiveDefinitions |
46
|
|
|
*/ |
47
|
|
|
public function __construct( |
48
|
|
|
SchemaInterface $schema, |
49
|
|
|
DocumentNode $document, |
50
|
|
|
array $typeDefinitionMap, |
51
|
|
|
array $typeExtensionsMap, |
52
|
|
|
array $directiveDefinitions |
53
|
|
|
) { |
54
|
|
|
$this->schema = $schema; |
55
|
|
|
$this->document = $document; |
56
|
|
|
$this->typeDefinitionMap = $typeDefinitionMap; |
57
|
|
|
$this->typeExtensionsMap = $typeExtensionsMap; |
58
|
|
|
$this->directiveDefinitions = $directiveDefinitions; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $typeName |
63
|
|
|
* @return bool |
64
|
|
|
*/ |
65
|
|
|
public function hasTypeExtensions(string $typeName): bool |
66
|
|
|
{ |
67
|
|
|
return isset($this->typeExtensionsMap[$typeName]); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $typeName |
72
|
|
|
* @return InterfaceTypeExtensionNode[]|ObjectTypeExtensionNode[]|null |
73
|
|
|
*/ |
74
|
|
|
public function getTypeExtensions(string $typeName): ?array |
75
|
|
|
{ |
76
|
|
|
return $this->typeExtensionsMap[$typeName] ?? null; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return SchemaInterface |
81
|
|
|
*/ |
82
|
|
|
public function getSchema(): SchemaInterface |
83
|
|
|
{ |
84
|
|
|
return $this->schema; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return DocumentNode |
89
|
|
|
*/ |
90
|
|
|
public function getDocument(): DocumentNode |
91
|
|
|
{ |
92
|
|
|
return $this->document; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return bool |
97
|
|
|
*/ |
98
|
|
|
public function hasTypeDefinitionMap(): bool |
99
|
|
|
{ |
100
|
|
|
return !empty($this->typeDefinitionMap); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return TypeDefinitionNodeInterface[] |
105
|
|
|
*/ |
106
|
|
|
public function getTypeDefinitionMap(): array |
107
|
|
|
{ |
108
|
|
|
return $this->typeDefinitionMap; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return bool |
113
|
|
|
*/ |
114
|
|
|
public function hasTypeExtensionsMap(): bool |
115
|
|
|
{ |
116
|
|
|
return !empty($this->typeExtensionsMap); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return InterfaceTypeExtensionNode[][]|ObjectTypeExtensionNode[][] |
121
|
|
|
*/ |
122
|
|
|
public function getTypeExtensionsMap() |
123
|
|
|
{ |
124
|
|
|
return $this->typeExtensionsMap; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return bool |
129
|
|
|
*/ |
130
|
|
|
public function hasDirectiveDefinitions(): bool |
131
|
|
|
{ |
132
|
|
|
return !empty($this->directiveDefinitions); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return DirectiveDefinitionNode[] |
137
|
|
|
*/ |
138
|
|
|
public function getDirectiveDefinitions(): array |
139
|
|
|
{ |
140
|
|
|
return $this->directiveDefinitions; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|