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\PolymorphicDefinitionInterface; |
14
|
|
|
|
15
|
|
|
trait PolymorphicDefinitionTrait |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Key:Value pair array containing the source and expected type |
19
|
|
|
* |
20
|
|
|
* ["App\Entity\User"=> "User", "App\Entity\Post" => "Post"] |
21
|
|
|
* |
22
|
|
|
* in case use union based on property: |
23
|
|
|
* |
24
|
|
|
* ["ADMIN"=> "AdminUser", "NORMAL" => "NormalUser"] |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
public $discriminatorMap = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* When use MODE_PROPERTY is the property to get the type |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
public $discriminatorProperty; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Name of the class or service to resolve the type |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
public $typeResolver; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function getDiscriminatorMap(): array |
48
|
|
|
{ |
49
|
|
|
return $this->discriminatorMap; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array $discriminatorMap |
54
|
|
|
* |
55
|
|
|
* @return PolymorphicDefinitionInterface |
56
|
|
|
*/ |
57
|
|
|
public function setDiscriminatorMap(array $discriminatorMap): PolymorphicDefinitionInterface |
58
|
|
|
{ |
59
|
|
|
$this->discriminatorMap = $discriminatorMap; |
60
|
|
|
|
61
|
|
|
return $this; |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getDiscriminatorProperty(): ?string |
68
|
|
|
{ |
69
|
|
|
return $this->discriminatorProperty; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string $discriminatorProperty |
74
|
|
|
* |
75
|
|
|
* @return PolymorphicDefinitionInterface |
76
|
|
|
*/ |
77
|
|
|
public function setDiscriminatorProperty(?string $discriminatorProperty): PolymorphicDefinitionInterface |
78
|
|
|
{ |
79
|
|
|
$this->discriminatorProperty = $discriminatorProperty; |
80
|
|
|
|
81
|
|
|
return $this; |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getTypeResolver(): string |
88
|
|
|
{ |
89
|
|
|
return $this->typeResolver; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $typeResolver |
94
|
|
|
* |
95
|
|
|
* @return PolymorphicDefinitionInterface |
96
|
|
|
*/ |
97
|
|
|
public function setTypeResolver(string $typeResolver): PolymorphicDefinitionInterface |
98
|
|
|
{ |
99
|
|
|
$this->typeResolver = $typeResolver; |
100
|
|
|
|
101
|
|
|
return $this; |
|
|
|
|
102
|
|
|
} |
103
|
|
|
} |