-
-
Notifications
You must be signed in to change notification settings - Fork 466
Expand file tree
/
Copy pathArgument.php
More file actions
74 lines (60 loc) · 1.89 KB
/
Argument.php
File metadata and controls
74 lines (60 loc) · 1.89 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
<?php declare(strict_types=1);
namespace Nuwave\Lighthouse\Execution\Arguments;
use Illuminate\Support\Collection;
use Nuwave\Lighthouse\Support\Contracts\ArgResolver;
class Argument
{
/**
* The value given by the client.
*
* @var ArgumentSet|array<\Nuwave\Lighthouse\Execution\Arguments\ArgumentSet>|mixed|array<mixed>
*/
public mixed $value;
/** The type of the argument. */
public ListType|NamedType|null $type = null;
/**
* A list of directives associated with that argument.
*
* @var \Illuminate\Support\Collection<int, \Nuwave\Lighthouse\Support\Contracts\Directive>
*/
public Collection $directives;
/** A resolver that handles the given value. */
public ?ArgResolver $resolver = null;
public function __construct()
{
$this->directives = new Collection();
}
/** Get the plain PHP value of this argument. */
public function toPlain(): mixed
{
return static::toPlainRecursive($this->value);
}
public function namedType(): ?NamedType
{
return static::namedTypeRecursive($this->type);
}
protected static function namedTypeRecursive(ListType|NamedType|null $type): ?NamedType
{
if ($type instanceof ListType) {
return static::namedTypeRecursive($type->type);
}
return $type;
}
/**
* Convert the given value to plain PHP values recursively.
*
* @param ArgumentSet|array<\Nuwave\Lighthouse\Execution\Arguments\ArgumentSet>|mixed|array<mixed> $value
*
* @return mixed|array<mixed>
*/
protected static function toPlainRecursive(mixed $value): mixed
{
if ($value instanceof ArgumentSet) {
return $value->toArray();
}
if (is_array($value)) {
return array_map([static::class, 'toPlainRecursive'], $value);
}
return $value;
}
}