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