Completed
Pull Request — master (#217)
by Christoffer
02:55
created

ExecutionContext::createExecutor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Digia\GraphQL\Execution;
4
5
use Digia\GraphQL\Error\ExecutionException;
6
use Digia\GraphQL\Language\Node\FragmentDefinitionNode;
7
use Digia\GraphQL\Language\Node\OperationDefinitionNode;
8
use Digia\GraphQL\Schema\Schema;
9
10
class ExecutionContext
11
{
12
    /**
13
     * @var Schema
14
     */
15
    protected $schema;
16
17
    /**
18
     * @var FragmentDefinitionNode[]
19
     */
20
    protected $fragments;
21
22
    /**
23
     * @var mixed
24
     */
25
    protected $rootValue;
26
27
    /**
28
     * @var mixed
29
     */
30
    protected $contextValue;
31
32
    /**
33
     * @var mixed
34
     */
35
    protected $variableValues;
36
37
    /**
38
     * @var mixed
39
     */
40
    protected $fieldResolver;
41
42
    /**
43
     * @var OperationDefinitionNode
44
     */
45
    protected $operation;
46
47
    /**
48
     * @var ExecutionException[]
49
     */
50
    protected $errors;
51
52
    /**
53
     * ExecutionContext constructor.
54
     * @param Schema                  $schema
55
     * @param array                   $fragments
56
     * @param mixed                   $rootValue
57
     * @param mixed                   $contextValue
58
     * @param mixed                   $variableValues
59
     * @param mixed                   $fieldResolver
60
     * @param OperationDefinitionNode $operation
61
     * @param array                   $errors
62
     */
63
    public function __construct(
64
        Schema $schema,
65
        array $fragments,
66
        $rootValue,
67
        $contextValue,
68
        $variableValues,
69
        $fieldResolver,
70
        OperationDefinitionNode $operation,
71
        array $errors
72
    ) {
73
        $this->schema         = $schema;
74
        $this->fragments      = $fragments;
75
        $this->rootValue      = $rootValue;
76
        $this->contextValue   = $contextValue;
77
        $this->variableValues = $variableValues;
78
        $this->fieldResolver  = $fieldResolver;
79
        $this->operation      = $operation;
80
        $this->errors         = $errors;
81
    }
82
83
    /**
84
     * @return mixed
85
     */
86
    public function getRootValue()
87
    {
88
        return $this->rootValue;
89
    }
90
91
    /**
92
     * @param mixed $rootValue
93
     * @return ExecutionContext
94
     */
95
    public function setRootValue($rootValue): ExecutionContext
96
    {
97
        $this->rootValue = $rootValue;
98
        return $this;
99
    }
100
101
    /**
102
     * @return mixed
103
     */
104
    public function getContextValue()
105
    {
106
        return $this->contextValue ?? [];
107
    }
108
109
    /**
110
     * @param mixed $contextValue
111
     * @return ExecutionContext
112
     */
113
    public function setContextValue($contextValue): ExecutionContext
114
    {
115
        $this->contextValue = $contextValue;
116
        return $this;
117
    }
118
119
    /**
120
     * @return mixed
121
     */
122
    public function getVariableValues()
123
    {
124
        return $this->variableValues;
125
    }
126
127
    /**
128
     * @param mixed $variableValues
129
     * @return ExecutionContext
130
     */
131
    public function setVariableValues($variableValues): ExecutionContext
132
    {
133
        $this->variableValues = $variableValues;
134
        return $this;
135
    }
136
137
    /**
138
     * @return mixed
139
     */
140
    public function getFieldResolver()
141
    {
142
        return $this->fieldResolver;
143
    }
144
145
    /**
146
     * @param mixed $fieldResolver
147
     * @return ExecutionContext
148
     */
149
    public function setFieldResolver($fieldResolver): ExecutionContext
150
    {
151
        $this->fieldResolver = $fieldResolver;
152
        return $this;
153
    }
154
155
156
    /**
157
     * @return OperationDefinitionNode
158
     */
159
    public function getOperation(): OperationDefinitionNode
160
    {
161
        return $this->operation;
162
    }
163
164
    /**
165
     * @return Schema
166
     */
167
    public function getSchema(): Schema
168
    {
169
        return $this->schema;
170
    }
171
172
    /**
173
     * @return FragmentDefinitionNode[]
174
     */
175
    public function getFragments(): array
176
    {
177
        return $this->fragments;
178
    }
179
180
    /**
181
     * @param ExecutionException $error
182
     * @return ExecutionContext
183
     */
184
    public function addError(ExecutionException $error): ExecutionContext
185
    {
186
        $this->errors[] = $error;
187
        return $this;
188
    }
189
190
    /**
191
     * @return ExecutionException[]
192
     */
193
    public function getErrors(): array
194
    {
195
        return $this->errors;
196
    }
197
}
198