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\Backend; |
13
|
|
|
|
14
|
|
|
use Railt\SDL\Backend\Context\DefinitionContextInterface; |
15
|
|
|
use Railt\SDL\Backend\Runtime\ExecutionInterface; |
16
|
|
|
use Railt\TypeSystem\Reference\TypeReferenceInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Context |
20
|
|
|
*/ |
21
|
|
|
class Context |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var TypeReferenceInterface|null |
25
|
|
|
*/ |
26
|
|
|
private ?TypeReferenceInterface $query = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var TypeReferenceInterface|null |
30
|
|
|
*/ |
31
|
|
|
private ?TypeReferenceInterface $mutation = null; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var TypeReferenceInterface|null |
35
|
|
|
*/ |
36
|
|
|
private ?TypeReferenceInterface $subscription = null; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var array|DefinitionContextInterface[] |
40
|
|
|
*/ |
41
|
|
|
private array $types = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var array|DefinitionContextInterface[] |
45
|
|
|
*/ |
46
|
|
|
private array $directives = []; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var array|ExecutionInterface[] |
50
|
|
|
*/ |
51
|
|
|
private array $executions = []; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param ExecutionInterface $execution |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
|
|
public function addExecution(ExecutionInterface $execution): self |
58
|
|
|
{ |
59
|
|
|
$this->executions[] = $execution; |
60
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param TypeReferenceInterface|null $query |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function setQuery(?TypeReferenceInterface $query): void |
69
|
|
|
{ |
70
|
|
|
$this->query = $query; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param TypeReferenceInterface|null $mutation |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public function setMutation(?TypeReferenceInterface $mutation): void |
78
|
|
|
{ |
79
|
|
|
$this->mutation = $mutation; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param TypeReferenceInterface|null $subscription |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
|
|
public function setSubscription(?TypeReferenceInterface $subscription): void |
87
|
|
|
{ |
88
|
|
|
$this->subscription = $subscription; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return TypeReferenceInterface|null |
93
|
|
|
*/ |
94
|
|
|
public function getQuery(): ?TypeReferenceInterface |
95
|
|
|
{ |
96
|
|
|
return $this->query; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return TypeReferenceInterface|null |
101
|
|
|
*/ |
102
|
|
|
public function getMutation(): ?TypeReferenceInterface |
103
|
|
|
{ |
104
|
|
|
return $this->mutation; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return TypeReferenceInterface|null |
109
|
|
|
*/ |
110
|
|
|
public function getSubscription(): ?TypeReferenceInterface |
111
|
|
|
{ |
112
|
|
|
return $this->subscription; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return array|ExecutionInterface[] |
117
|
|
|
*/ |
118
|
|
|
public function getExecutions(): array |
119
|
|
|
{ |
120
|
|
|
return $this->executions; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param DefinitionContextInterface $type |
125
|
|
|
* @return $this |
126
|
|
|
*/ |
127
|
|
|
public function addType(DefinitionContextInterface $type): self |
128
|
|
|
{ |
129
|
|
|
$this->types[$type->getName()] = $type; |
130
|
|
|
|
131
|
|
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param string $name |
136
|
|
|
* @return bool |
137
|
|
|
*/ |
138
|
|
|
public function hasType(string $name): bool |
139
|
|
|
{ |
140
|
|
|
return isset($this->types[$name]); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return array|DefinitionContextInterface[] |
145
|
|
|
*/ |
146
|
|
|
public function getTypes(): array |
147
|
|
|
{ |
148
|
|
|
return $this->types; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param string $name |
153
|
|
|
* @return DefinitionContextInterface|null |
154
|
|
|
*/ |
155
|
|
|
public function getType(string $name): ?DefinitionContextInterface |
156
|
|
|
{ |
157
|
|
|
return $this->types[$name] ?? null; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param DefinitionContextInterface $type |
162
|
|
|
* @return $this |
163
|
|
|
*/ |
164
|
|
|
public function addDirective(DefinitionContextInterface $type): self |
165
|
|
|
{ |
166
|
|
|
$this->directives[$type->getName()] = $type; |
167
|
|
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param string $name |
173
|
|
|
* @return bool |
174
|
|
|
*/ |
175
|
|
|
public function hasDirective(string $name): bool |
176
|
|
|
{ |
177
|
|
|
return isset($this->directives[$name]); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return array|DefinitionContextInterface[] |
182
|
|
|
*/ |
183
|
|
|
public function getDirectives(): array |
184
|
|
|
{ |
185
|
|
|
return $this->directives; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $name |
190
|
|
|
* @return DefinitionContextInterface|null |
191
|
|
|
*/ |
192
|
|
|
public function getDirective(string $name): ?DefinitionContextInterface |
193
|
|
|
{ |
194
|
|
|
return $this->directives[$name] ?? null; |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|