1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Type\Definition; |
4
|
|
|
|
5
|
|
|
use Digia\GraphQL\Error\InvariantException; |
6
|
|
|
use Digia\GraphQL\Language\Node\ASTNodeAwareInterface; |
7
|
|
|
use Digia\GraphQL\Language\Node\ASTNodeTrait; |
8
|
|
|
use Digia\GraphQL\Language\Node\DirectiveDefinitionNode; |
9
|
|
|
use Digia\GraphQL\Schema\Definition; |
10
|
|
|
use GraphQL\Contracts\TypeSystem\DirectiveInterface; |
11
|
|
|
|
12
|
|
|
class Directive extends Definition implements DirectiveInterface, ASTNodeAwareInterface |
13
|
|
|
{ |
14
|
|
|
use NameTrait; |
15
|
|
|
use DescriptionTrait; |
16
|
|
|
use ArgumentsTrait; |
17
|
|
|
use ASTNodeTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string[] |
21
|
|
|
*/ |
22
|
|
|
protected $locations; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Directive constructor. |
26
|
|
|
* |
27
|
|
|
* @param string $name |
28
|
|
|
* @param null|string $description |
29
|
|
|
* @param string[] $locations |
30
|
|
|
* @param array $rawArguments |
31
|
|
|
* @param DirectiveDefinitionNode|null $astNode |
32
|
|
|
* @param string $typeName |
33
|
|
|
* @throws InvariantException |
34
|
|
|
*/ |
35
|
|
|
public function __construct( |
36
|
|
|
string $name, |
37
|
|
|
?string $description, |
38
|
|
|
array $locations, |
39
|
|
|
array $rawArguments, |
40
|
|
|
?DirectiveDefinitionNode $astNode, |
41
|
|
|
string $typeName |
42
|
|
|
) { |
43
|
|
|
$this->name = $name; |
44
|
|
|
$this->description = $description; |
45
|
|
|
$this->locations = $locations; |
46
|
|
|
$this->rawArguments = $rawArguments; |
47
|
|
|
$this->astNode = $astNode; |
48
|
|
|
|
49
|
|
|
$this->arguments = $this->buildArguments($typeName, $this->rawArguments); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritDoc} |
54
|
|
|
*/ |
55
|
|
|
public function getLocations(): array |
56
|
|
|
{ |
57
|
|
|
return $this->locations; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritDoc} |
62
|
|
|
*/ |
63
|
|
|
public function hasLocation(string $name): bool |
64
|
|
|
{ |
65
|
|
|
return isset($this->locations[$name]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritDoc} |
70
|
|
|
*/ |
71
|
|
|
public function isRepeatable(): bool |
72
|
|
|
{ |
73
|
|
|
throw new \LogicException(__METHOD__ . ' not supported yet'); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|