1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Railt package. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Railt\SDL; |
13
|
|
|
|
14
|
|
|
use Railt\SDL\Runtime\ExecutionInterface; |
15
|
|
|
use GraphQL\Contracts\TypeSystem\SchemaInterface; |
16
|
|
|
use GraphQL\Contracts\TypeSystem\DirectiveInterface; |
17
|
|
|
use GraphQL\Contracts\TypeSystem\Type\NamedTypeInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Document |
21
|
|
|
*/ |
22
|
|
|
final class Document implements DocumentInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var array|NamedTypeInterface[] |
26
|
|
|
*/ |
27
|
|
|
private array $typeMap = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array|DirectiveInterface[] |
31
|
|
|
*/ |
32
|
|
|
private array $directives = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array|ExecutionInterface[] |
36
|
|
|
*/ |
37
|
|
|
private array $executions = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var SchemaInterface|null |
41
|
|
|
*/ |
42
|
|
|
private ?SchemaInterface $schema = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritDoc} |
46
|
|
|
*/ |
47
|
|
|
public function getType(string $name): ?NamedTypeInterface |
48
|
|
|
{ |
49
|
|
|
return $this->typeMap[$name] ?? null; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritDoc} |
54
|
|
|
*/ |
55
|
|
|
public function hasType(string $name): bool |
56
|
|
|
{ |
57
|
|
|
return isset($this->typeMap[$name]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param NamedTypeInterface $type |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function addType(NamedTypeInterface $type): void |
65
|
|
|
{ |
66
|
|
|
$this->typeMap[$type->getName()] = $type; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
*/ |
72
|
|
|
public function getDirective(string $name): ?DirectiveInterface |
73
|
|
|
{ |
74
|
|
|
return $this->directives[$name] ?? null; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritDoc} |
79
|
|
|
*/ |
80
|
|
|
public function hasDirective(string $name): bool |
81
|
|
|
{ |
82
|
|
|
return isset($this->directives[$name]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param DirectiveInterface $directive |
87
|
|
|
* @return void |
88
|
|
|
*/ |
89
|
|
|
public function addDirective(DirectiveInterface $directive): void |
90
|
|
|
{ |
91
|
|
|
$this->directives[$directive->getName()] = $directive; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return iterable|ExecutionInterface[] |
96
|
|
|
*/ |
97
|
|
|
public function getExecutions(): iterable |
98
|
|
|
{ |
99
|
|
|
return $this->executions; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param ExecutionInterface $execution |
104
|
|
|
* @return void |
105
|
|
|
*/ |
106
|
|
|
public function addExecution(ExecutionInterface $execution): void |
107
|
|
|
{ |
108
|
|
|
$this->executions[] = $execution; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* {@inheritDoc} |
113
|
|
|
*/ |
114
|
|
|
public function getTypes(): iterable |
115
|
|
|
{ |
116
|
|
|
return $this->typeMap; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* {@inheritDoc} |
121
|
|
|
*/ |
122
|
|
|
public function getDirectives(): iterable |
123
|
|
|
{ |
124
|
|
|
return $this->directives; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* {@inheritDoc} |
129
|
|
|
*/ |
130
|
|
|
public function getSchema(): ?SchemaInterface |
131
|
|
|
{ |
132
|
|
|
return $this->schema; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param SchemaInterface|null $schema |
137
|
|
|
* @return void |
138
|
|
|
*/ |
139
|
|
|
public function setSchema(?SchemaInterface $schema): void |
140
|
|
|
{ |
141
|
|
|
$this->schema = $schema; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|