1
|
|
|
<?php |
2
|
|
|
/******************************************************************************* |
3
|
|
|
* This file is part of the GraphQL Bundle package. |
4
|
|
|
* |
5
|
|
|
* (c) YnloUltratech <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
******************************************************************************/ |
10
|
|
|
|
11
|
|
|
namespace Ynlo\GraphQLBundle\Definition\Traits; |
12
|
|
|
|
13
|
|
|
use Ynlo\GraphQLBundle\Definition\FieldDefinition; |
14
|
|
|
use Ynlo\GraphQLBundle\Definition\FieldsAwareDefinitionInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Trait FieldsAwareDefinitionTrait |
18
|
|
|
*/ |
19
|
|
|
trait FieldsAwareDefinitionTrait |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var FieldDefinition[] |
23
|
|
|
*/ |
24
|
|
|
protected $fields = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return array|FieldDefinition[] |
28
|
|
|
*/ |
29
|
33 |
|
public function getFields(): array |
30
|
|
|
{ |
31
|
33 |
|
return $this->fields; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $name |
36
|
|
|
* |
37
|
|
|
* @return FieldDefinition |
38
|
|
|
*/ |
39
|
36 |
|
public function getField(string $name): FieldDefinition |
40
|
|
|
{ |
41
|
36 |
|
return $this->fields[$name]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $name |
46
|
|
|
* |
47
|
|
|
* @return boolean |
48
|
|
|
*/ |
49
|
39 |
|
public function hasField(string $name): bool |
50
|
|
|
{ |
51
|
39 |
|
return array_key_exists($name, $this->fields); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param FieldDefinition $field |
56
|
|
|
* |
57
|
|
|
* @return FieldsAwareDefinitionInterface |
58
|
|
|
*/ |
59
|
38 |
|
public function addField(FieldDefinition $field): FieldsAwareDefinitionInterface |
60
|
|
|
{ |
61
|
38 |
|
$this->fields[$field->getName()] = $field; |
62
|
|
|
|
63
|
38 |
|
return $this; |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $name |
68
|
|
|
* |
69
|
|
|
* @return FieldsAwareDefinitionInterface |
70
|
|
|
*/ |
71
|
32 |
|
public function removeField(string $name): FieldsAwareDefinitionInterface |
72
|
|
|
{ |
73
|
32 |
|
unset($this->fields[$name]); |
74
|
|
|
|
75
|
32 |
|
return $this; |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param FieldDefinition $field |
80
|
|
|
* |
81
|
|
|
* @return FieldsAwareDefinitionInterface |
82
|
|
|
*/ |
83
|
1 |
|
public function prependField(FieldDefinition $field): FieldsAwareDefinitionInterface |
84
|
|
|
{ |
85
|
1 |
|
$this->fields = array_merge([$field->getName() => $field], $this->fields); |
86
|
|
|
|
87
|
1 |
|
return $this; |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|