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\Resolver; |
12
|
|
|
|
13
|
|
|
use Doctrine\ORM\EntityManager; |
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
16
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
17
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
18
|
|
|
use Ynlo\GraphQLBundle\Extension\ExtensionInterface; |
19
|
|
|
use Ynlo\GraphQLBundle\Extension\ExtensionsAwareInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* AbstractResolver is a simple implementation of a Resolver. |
23
|
|
|
* |
24
|
|
|
* It provides methods to common features needed in resolvers. |
25
|
|
|
*/ |
26
|
|
|
abstract class AbstractResolver implements ExtensionsAwareInterface, ContainerAwareInterface |
27
|
|
|
{ |
28
|
|
|
use ContainerAwareTrait; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var ResolverContext |
32
|
|
|
*/ |
33
|
|
|
protected $context; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var ExtensionInterface[] |
37
|
|
|
*/ |
38
|
|
|
protected $extensions = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritDoc} |
42
|
|
|
*/ |
43
|
21 |
|
public function setExtensions($extensions) |
44
|
|
|
{ |
45
|
21 |
|
$this->extensions = $extensions; |
46
|
21 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return ResolverContext |
50
|
|
|
*/ |
51
|
13 |
|
public function getContext(): ResolverContext |
52
|
|
|
{ |
53
|
13 |
|
return $this->context; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param ResolverContext $context |
58
|
|
|
*/ |
59
|
21 |
|
public function setContext(ResolverContext $context) |
60
|
|
|
{ |
61
|
21 |
|
$this->context = $context; |
62
|
21 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Gets a container service by its id. |
66
|
|
|
* |
67
|
|
|
* @param string $id The service id |
68
|
|
|
* |
69
|
|
|
* @return mixed The service |
70
|
|
|
*/ |
71
|
21 |
|
protected function get($id) |
72
|
|
|
{ |
73
|
21 |
|
return $this->container->get($id); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return EntityManager |
78
|
|
|
*/ |
79
|
21 |
|
protected function getManager(): EntityManager |
80
|
|
|
{ |
81
|
21 |
|
return $this->get('doctrine')->getManager(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return ValidatorInterface |
86
|
|
|
*/ |
87
|
|
|
protected function getValidator(): ValidatorInterface |
88
|
|
|
{ |
89
|
|
|
return $this->get('validator'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Creates and returns a Form Builder instance from the type of the form. |
94
|
|
|
* |
95
|
|
|
* @param string $type The fully qualified class name of the form type |
96
|
|
|
* @param mixed $data The initial data for the form |
97
|
|
|
* @param array $options Options for the form |
98
|
|
|
* |
99
|
|
|
* @return FormBuilderInterface |
100
|
|
|
*/ |
101
|
8 |
|
protected function createFormBuilder($type, $data = null, array $options = []) |
102
|
|
|
{ |
103
|
8 |
|
return $this->container->get('form.factory')->createBuilder($type, $data, $options); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|