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\Frontend\Ast\Definition; |
13
|
|
|
|
14
|
|
|
use Railt\SDL\Frontend\Ast\DefinitionNode; |
15
|
|
|
use Railt\SDL\Frontend\Ast\Description; |
16
|
|
|
use Railt\SDL\Frontend\Ast\Executable\DirectiveNode; |
17
|
|
|
use Railt\SDL\Frontend\Ast\Identifier; |
18
|
|
|
use Railt\SDL\Frontend\Ast\Node; |
19
|
|
|
use Railt\SDL\Frontend\Ast\Type\TypeNode; |
20
|
|
|
use Railt\TypeSystem\Value\StringValue; |
21
|
|
|
use Railt\TypeSystem\Value\ValueInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class InputValueDefinitionNode |
25
|
|
|
* |
26
|
|
|
* <code> |
27
|
|
|
* export interface InputValueDefinitionNode { |
28
|
|
|
* readonly kind: 'InputValueDefinition'; |
29
|
|
|
* readonly loc?: Location; |
30
|
|
|
* readonly description?: StringValueNode; |
31
|
|
|
* readonly name: IdentifierNode; |
32
|
|
|
* readonly type: TypeNode; |
33
|
|
|
* readonly defaultValue?: ValueNode; |
34
|
|
|
* readonly directives?: ReadonlyArray<DirectiveNode>; |
35
|
|
|
* } |
36
|
|
|
* </code> |
37
|
|
|
*/ |
38
|
|
|
class InputFieldDefinitionNode extends DefinitionNode |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* @var Identifier |
42
|
|
|
*/ |
43
|
|
|
public Identifier $name; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var TypeNode |
47
|
|
|
*/ |
48
|
|
|
public TypeNode $type; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var StringValue|null |
52
|
|
|
*/ |
53
|
|
|
public ?StringValue $description = null; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var DirectiveNode[] |
57
|
|
|
*/ |
58
|
|
|
public array $directives = []; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var ValueInterface|null |
62
|
|
|
*/ |
63
|
|
|
public ?ValueInterface $defaultValue = null; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* TypeDefinitionNode constructor. |
67
|
|
|
* |
68
|
|
|
* @param Identifier $name |
69
|
|
|
* @param TypeNode $type |
70
|
|
|
*/ |
71
|
|
|
public function __construct(Identifier $name, TypeNode $type) |
72
|
|
|
{ |
73
|
|
|
$this->name = $name; |
74
|
|
|
$this->type = $type; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param array|Node[] $children |
79
|
|
|
* @return static |
80
|
|
|
*/ |
81
|
|
|
public static function create(array $children): self |
82
|
|
|
{ |
83
|
|
|
$field = new static($children[1], $children[2]); |
84
|
|
|
|
85
|
|
|
foreach ($children as $child) { |
86
|
|
|
switch (true) { |
87
|
|
|
case $child instanceof Description: |
88
|
|
|
$field->description = $child->value; |
89
|
|
|
break; |
90
|
|
|
|
91
|
|
|
case $child instanceof DirectiveNode: |
92
|
|
|
$field->directives[] = $child; |
93
|
|
|
break; |
94
|
|
|
|
95
|
|
|
case $child instanceof ValueInterface: |
96
|
|
|
$field->defaultValue = $child; |
97
|
|
|
break; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $field; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|