|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Date: 23.11.15 |
|
4
|
|
|
* |
|
5
|
|
|
* @author Portey Vasil <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Youshido\GraphQL; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
use Youshido\GraphQL\Parser\Ast\Fragment; |
|
12
|
|
|
use Youshido\GraphQL\Parser\Ast\Mutation; |
|
13
|
|
|
use Youshido\GraphQL\Parser\Ast\Query; |
|
14
|
|
|
|
|
15
|
|
|
class Request |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** @var Query[] */ |
|
19
|
|
|
private $queries = []; |
|
20
|
|
|
|
|
21
|
|
|
/** @var Fragment[] */ |
|
22
|
|
|
private $fragments = []; |
|
23
|
|
|
|
|
24
|
|
|
/** @var Mutation[] */ |
|
25
|
|
|
private $mutations = []; |
|
26
|
|
|
|
|
27
|
|
|
/** @var array */ |
|
28
|
|
|
private $variables = []; |
|
29
|
|
|
|
|
30
|
13 |
|
public function __construct($data = []) |
|
31
|
|
|
{ |
|
32
|
13 |
|
if (array_key_exists('queries', $data)) { |
|
33
|
13 |
|
$this->addQueries($data['queries']); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
13 |
|
if (array_key_exists('mutations', $data)) { |
|
37
|
13 |
|
$this->addMutations($data['mutations']); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
13 |
|
if (array_key_exists('fragments', $data)) { |
|
41
|
13 |
|
$this->addFragments($data['fragments']); |
|
42
|
|
|
} |
|
43
|
13 |
|
} |
|
44
|
|
|
|
|
45
|
13 |
|
public function addQueries($queries) |
|
46
|
|
|
{ |
|
47
|
13 |
|
foreach ($queries as $query) { |
|
48
|
13 |
|
$this->queries[] = $query; |
|
49
|
|
|
} |
|
50
|
13 |
|
} |
|
51
|
|
|
|
|
52
|
13 |
|
public function addMutations($mutations) |
|
53
|
|
|
{ |
|
54
|
13 |
|
foreach ($mutations as $mutation) { |
|
55
|
|
|
$this->mutations[] = $mutation; |
|
56
|
|
|
} |
|
57
|
13 |
|
} |
|
58
|
|
|
|
|
59
|
13 |
|
public function addFragments($fragments) |
|
60
|
|
|
{ |
|
61
|
13 |
|
foreach ($fragments as $fragment) { |
|
62
|
|
|
$this->fragments[] = $fragment; |
|
63
|
|
|
} |
|
64
|
13 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return Query[] |
|
68
|
|
|
*/ |
|
69
|
13 |
|
public function getQueries() |
|
70
|
|
|
{ |
|
71
|
13 |
|
return $this->queries; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return Fragment[] |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getFragments() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->fragments; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function addFragment($fragment) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->fragments[] = $fragment; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return Mutation[] |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getMutations() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->mutations; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return bool |
|
97
|
|
|
*/ |
|
98
|
13 |
|
public function hasQueries() |
|
99
|
|
|
{ |
|
100
|
13 |
|
return (bool)count($this->queries); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return bool |
|
105
|
|
|
*/ |
|
106
|
13 |
|
public function hasMutations() |
|
107
|
|
|
{ |
|
108
|
13 |
|
return (bool)count($this->mutations); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return bool |
|
113
|
|
|
*/ |
|
114
|
|
|
public function hasFragments() |
|
115
|
|
|
{ |
|
116
|
|
|
return (bool)count($this->fragments); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return array |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getVariables() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->variables; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @param array $variables |
|
129
|
|
|
*/ |
|
130
|
13 |
|
public function setVariables($variables) |
|
131
|
|
|
{ |
|
132
|
13 |
|
$this->variables = $variables; |
|
133
|
13 |
|
} |
|
134
|
|
|
|
|
135
|
1 |
|
public function getVariable($name) |
|
136
|
|
|
{ |
|
137
|
1 |
|
return $this->hasVariable($name) ? $this->variables[$name] : null; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
1 |
|
public function hasVariable($name) |
|
141
|
|
|
{ |
|
142
|
1 |
|
return array_key_exists($name, $this->variables); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @param $name |
|
147
|
|
|
* |
|
148
|
|
|
* @return null|Fragment |
|
149
|
|
|
*/ |
|
150
|
|
|
public function getFragment($name) |
|
151
|
|
|
{ |
|
152
|
|
|
foreach ($this->fragments as $fragment) { |
|
153
|
|
|
if ($fragment->getName() == $name) { |
|
154
|
|
|
return $fragment; |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
return null; |
|
159
|
|
|
} |
|
160
|
|
|
} |