|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
18
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
19
|
|
|
|
|
20
|
|
|
class OverblogGraphQLExtension extends Extension implements PrependExtensionInterface |
|
21
|
|
|
{ |
|
22
|
31 |
|
public function load(array $configs, ContainerBuilder $container) |
|
23
|
|
|
{ |
|
24
|
31 |
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
25
|
31 |
|
$loader->load('services.yml'); |
|
26
|
31 |
|
$loader->load('graphql_types.yml'); |
|
27
|
31 |
|
$loader->load('graphql_fields.yml'); |
|
28
|
31 |
|
$loader->load('graphql_args.yml'); |
|
29
|
|
|
|
|
30
|
31 |
|
$configuration = $this->getConfiguration($configs, $container); |
|
31
|
31 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
32
|
|
|
|
|
33
|
31 |
|
$this->setServicesAliases($config, $container); |
|
34
|
31 |
|
$this->setSchemaBuilderArguments($config, $container); |
|
35
|
31 |
|
$this->setSchemaArguments($config, $container); |
|
36
|
31 |
|
$this->setErrorHandlerArguments($config, $container); |
|
37
|
31 |
|
$this->setGraphiQLTemplate($config, $container); |
|
38
|
31 |
|
} |
|
39
|
|
|
|
|
40
|
31 |
|
public function prepend(ContainerBuilder $container) |
|
41
|
|
|
{ |
|
42
|
31 |
|
$configs = $container->getExtensionConfig($this->getAlias()); |
|
43
|
31 |
|
$configs = $container->getParameterBag()->resolveValue($configs); |
|
44
|
31 |
|
$configuration = $this->getConfiguration($configs, $container); |
|
45
|
31 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
46
|
|
|
|
|
47
|
|
|
/** @var OverblogGraphQLTypesExtension $typesExtension */ |
|
48
|
31 |
|
$typesExtension = $container->getExtension($this->getAlias().'_types'); |
|
49
|
31 |
|
$typesExtension->containerPrependExtensionConfig($config, $container); |
|
50
|
31 |
|
} |
|
51
|
|
|
|
|
52
|
31 |
|
private function setGraphiQLTemplate(array $config, ContainerBuilder $container) |
|
53
|
|
|
{ |
|
54
|
31 |
|
if (isset($config['templates']['graphiql'])) { |
|
55
|
31 |
|
$container->setParameter('overblog_graphql.graphiql_template', $config['templates']['graphiql']); |
|
56
|
31 |
|
} |
|
57
|
31 |
|
} |
|
58
|
|
|
|
|
59
|
31 |
|
private function setErrorHandlerArguments(array $config, ContainerBuilder $container) |
|
60
|
|
|
{ |
|
61
|
31 |
|
if (isset($config['definitions']['internal_error_message'])) { |
|
62
|
|
|
$container |
|
63
|
|
|
->getDefinition($this->getAlias().'.error_handler') |
|
64
|
|
|
->replaceArgument(0, $config['definitions']['internal_error_message']) |
|
65
|
|
|
->setPublic(true) |
|
66
|
|
|
; |
|
67
|
|
|
} |
|
68
|
31 |
|
} |
|
69
|
|
|
|
|
70
|
31 |
|
private function setSchemaBuilderArguments(array $config, ContainerBuilder $container) |
|
71
|
|
|
{ |
|
72
|
31 |
|
$container->getDefinition($this->getAlias().'.schema_builder') |
|
73
|
31 |
|
->replaceArgument(1, $config['definitions']['config_validation']); |
|
74
|
31 |
|
} |
|
75
|
|
|
|
|
76
|
31 |
|
private function setSchemaArguments(array $config, ContainerBuilder $container) |
|
77
|
|
|
{ |
|
78
|
31 |
|
if (isset($config['definitions']['schema'])) { |
|
79
|
|
|
$container |
|
80
|
31 |
|
->getDefinition($this->getAlias().'.schema') |
|
81
|
31 |
|
->replaceArgument(0, $config['definitions']['schema']['query']) |
|
82
|
31 |
|
->replaceArgument(1, $config['definitions']['schema']['mutation']) |
|
83
|
31 |
|
->replaceArgument(2, $config['definitions']['schema']['subscription']) |
|
84
|
31 |
|
->setPublic(true) |
|
85
|
|
|
; |
|
86
|
31 |
|
} |
|
87
|
31 |
|
} |
|
88
|
|
|
|
|
89
|
31 |
|
private function setServicesAliases(array $config, ContainerBuilder $container) |
|
90
|
|
|
{ |
|
91
|
31 |
|
if (isset($config['services'])) { |
|
92
|
31 |
|
foreach ($config['services'] as $name => $id) { |
|
93
|
31 |
|
$alias = sprintf('%s.%s', $this->getAlias(), $name); |
|
94
|
31 |
|
$container->setAlias($alias, $id); |
|
95
|
31 |
|
} |
|
96
|
31 |
|
} |
|
97
|
31 |
|
} |
|
98
|
|
|
|
|
99
|
31 |
|
public function getAlias() |
|
100
|
|
|
{ |
|
101
|
31 |
|
return 'overblog_graphql'; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
31 |
|
public function getConfiguration(array $config, ContainerBuilder $container) |
|
105
|
|
|
{ |
|
106
|
31 |
|
return new Configuration($container->getParameter('kernel.debug')); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|