|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Date: 23.11.15 |
|
4
|
|
|
* |
|
5
|
|
|
* @author Portey Vasil <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Youshido\GraphQL\Parser\Ast\ArgumentValue; |
|
9
|
|
|
|
|
10
|
|
|
use Youshido\GraphQL\Parser\Ast\AbstractAst; |
|
11
|
|
|
use Youshido\GraphQL\Parser\Ast\Interfaces\ValueInterface; |
|
12
|
|
|
use Youshido\GraphQL\Parser\Location; |
|
13
|
|
|
|
|
14
|
|
|
class Variable extends AbstractAst implements ValueInterface |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
private $name; |
|
19
|
|
|
|
|
20
|
|
|
/** @var mixed */ |
|
21
|
|
|
private $value; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
private $type; |
|
25
|
|
|
|
|
26
|
|
|
/** @var bool */ |
|
27
|
|
|
private $nullable = false; |
|
28
|
|
|
|
|
29
|
|
|
/** @var bool */ |
|
30
|
|
|
private $isArray = false; |
|
31
|
|
|
|
|
32
|
|
|
/** @var bool */ |
|
33
|
|
|
private $used = false; |
|
34
|
|
|
|
|
35
|
|
|
/** @var bool */ |
|
36
|
|
|
private $arrayElementNullable = true; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param string $name |
|
40
|
|
|
* @param string $type |
|
41
|
|
|
* @param bool $nullable |
|
42
|
|
|
* @param bool $isArray |
|
43
|
|
|
* @param Location $location |
|
44
|
|
|
* @param bool $arrayElementNullable |
|
45
|
|
|
*/ |
|
46
|
12 |
|
public function __construct($name, $type, $nullable, $isArray, Location $location, $arrayElementNullable = true) |
|
47
|
|
|
{ |
|
48
|
12 |
|
parent::__construct($location); |
|
49
|
|
|
|
|
50
|
12 |
|
$this->name = $name; |
|
51
|
12 |
|
$this->type = $type; |
|
52
|
12 |
|
$this->isArray = $isArray; |
|
53
|
12 |
|
$this->nullable = $nullable; |
|
54
|
12 |
|
$this->arrayElementNullable = $arrayElementNullable; |
|
55
|
12 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return mixed |
|
59
|
|
|
* |
|
60
|
|
|
* @throws \LogicException |
|
61
|
|
|
*/ |
|
62
|
4 |
|
public function getValue() |
|
63
|
|
|
{ |
|
64
|
4 |
|
if (null === $this->value) { |
|
65
|
2 |
|
throw new \LogicException('Value is not set for variable "' . $this->name . '"'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
2 |
|
return $this->value; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param mixed $value |
|
73
|
|
|
*/ |
|
74
|
2 |
|
public function setValue($value) |
|
75
|
|
|
{ |
|
76
|
2 |
|
$this->value = $value; |
|
77
|
2 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
9 |
|
public function getName() |
|
83
|
|
|
{ |
|
84
|
9 |
|
return $this->name; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param string $name |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function setName($name) |
|
91
|
|
|
{ |
|
92
|
1 |
|
$this->name = $name; |
|
93
|
1 |
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
6 |
|
public function getTypeName() |
|
99
|
|
|
{ |
|
100
|
6 |
|
return $this->type; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param string $type |
|
105
|
|
|
*/ |
|
106
|
1 |
|
public function setTypeName($type) |
|
107
|
|
|
{ |
|
108
|
1 |
|
$this->type = $type; |
|
109
|
1 |
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return boolean |
|
113
|
|
|
*/ |
|
114
|
2 |
|
public function isArray() |
|
115
|
|
|
{ |
|
116
|
2 |
|
return $this->isArray; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param boolean $isArray |
|
121
|
|
|
*/ |
|
122
|
1 |
|
public function setIsArray($isArray) |
|
123
|
|
|
{ |
|
124
|
1 |
|
$this->isArray = $isArray; |
|
125
|
1 |
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return boolean |
|
129
|
|
|
*/ |
|
130
|
2 |
|
public function isNullable() |
|
131
|
|
|
{ |
|
132
|
2 |
|
return $this->nullable; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param boolean $nullable |
|
137
|
|
|
*/ |
|
138
|
1 |
|
public function setNullable($nullable) |
|
139
|
|
|
{ |
|
140
|
1 |
|
$this->nullable = $nullable; |
|
141
|
1 |
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @return boolean |
|
145
|
|
|
*/ |
|
146
|
6 |
|
public function isUsed() |
|
147
|
|
|
{ |
|
148
|
6 |
|
return $this->used; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param boolean $used |
|
153
|
|
|
* |
|
154
|
|
|
* @return $this |
|
155
|
|
|
*/ |
|
156
|
7 |
|
public function setUsed($used) |
|
157
|
|
|
{ |
|
158
|
7 |
|
$this->used = $used; |
|
159
|
|
|
|
|
160
|
7 |
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @return bool |
|
165
|
|
|
*/ |
|
166
|
1 |
|
public function isArrayElementNullable() |
|
167
|
|
|
{ |
|
168
|
1 |
|
return $this->arrayElementNullable; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @param bool $arrayElementNullable |
|
173
|
|
|
*/ |
|
174
|
|
|
public function setArrayElementNullable($arrayElementNullable) |
|
175
|
|
|
{ |
|
176
|
|
|
$this->arrayElementNullable = $arrayElementNullable; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|