-
-
Notifications
You must be signed in to change notification settings - Fork 470
Expand file tree
/
Copy pathArgumentSet.php
More file actions
123 lines (99 loc) · 2.92 KB
/
ArgumentSet.php
File metadata and controls
123 lines (99 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace Nuwave\Lighthouse\Execution\Arguments;
class ArgumentSet implements \ArrayAccess, \IteratorAggregate
{
/**
* An associative array from argument names to arguments.
*
* @var array<string, \Nuwave\Lighthouse\Execution\Arguments\Argument>
*/
public $arguments = [];
/**
* An associative array of arguments that were not given.
*
* @var array<string, \Nuwave\Lighthouse\Execution\Arguments\Argument>
*/
public $undefined = [];
/**
* A list of directives.
*
* This may be coming from
* - the field the arguments are a part of
* - the parent argument when in a tree of nested inputs.
*
* @var \Illuminate\Support\Collection<\Nuwave\Lighthouse\Support\Contracts\Directive>
*/
public $directives;
/**
* Get a plain array representation of this ArgumentSet.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$plainArguments = [];
foreach ($this->arguments as $name => $argument) {
$plainArguments[$name] = $argument->toPlain();
}
return $plainArguments;
}
/**
* Check if the ArgumentSet has a non-null value with the given key.
*/
public function has(string $key): bool
{
$argument = $this->arguments[$key] ?? null;
if (! $argument instanceof Argument) {
return false;
}
return null !== $argument->value;
}
/**
* Add a value at the dot-separated path.
* Asterisks may be used to indicate wildcards.
*
* @param mixed $value any value to inject
*/
public function addValue(string $path, mixed $value): self
{
$argumentSet = $this;
data_set($argumentSet, $path, $value);
return $this;
}
/**
* The contained arguments, including all that were not passed.
*
* @return array<string, \Nuwave\Lighthouse\Execution\Arguments\Argument>
*/
public function argumentsWithUndefined(): array
{
return array_merge($this->arguments, $this->undefined);
}
public function offsetExists(mixed $offset): bool
{
$argumentSet = $this;
return isset($argumentSet->arguments[$offset]);
}
public function &offsetGet(mixed $offset): Argument
{
$argumentSet = $this;
return $argumentSet->arguments[$offset];
}
public function offsetSet(mixed $offset, mixed $value): void
{
$argumentSet = $this;
$argument = new Argument();
$argument->value = $value;
$argumentSet->arguments[(string) $offset] = $argument;
}
public function offsetUnset(mixed $offset): void
{
$argumentSet = $this;
unset($argumentSet->arguments[$offset]);
}
public function getIterator(): \ArrayIterator
{
$arguments = $this->arguments;
return new \ArrayIterator($arguments);
}
}