1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/******************************************************************************* |
4
|
|
|
* This file is part of the GraphQL Bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) YnloUltratech <[email protected]> |
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 Ynlo\GraphQLBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
17
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
18
|
|
|
use Ynlo\GraphQLBundle\Cache\DefinitionCacheWarmer; |
19
|
|
|
use Ynlo\GraphQLBundle\GraphiQL\JWTGraphiQLAuthentication; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class YnloGraphQLExtension |
23
|
|
|
*/ |
24
|
|
|
class YnloGraphQLExtension extends Extension |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
30
|
|
|
{ |
31
|
1 |
|
$configuration = new Configuration(); |
32
|
1 |
|
$config = $this->processConfiguration($configuration, $configs); |
33
|
|
|
|
34
|
1 |
|
if (!isset($config['definitions']['plugins']['namespaces']['bundles']['aliases']['GraphQLBundle'])) { |
35
|
1 |
|
$config['definitions']['plugins']['namespaces']['bundles']['aliases']['GraphQLBundle'] = 'AppBundle'; |
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
$container->setParameter('graphql.config', $config); |
39
|
1 |
|
if (isset($config['definitions']['plugins'])) { |
40
|
1 |
|
foreach ($config['definitions']['plugins'] as $plugin => $pluginConfig) { |
41
|
1 |
|
$pluginConfig = isset($pluginConfig['enabled']) && $pluginConfig['enabled'] ? $pluginConfig : []; |
42
|
1 |
|
$container->setParameter('graphql.plugin_config.'.$plugin, $pluginConfig ?? []); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
$container->setParameter('graphql.cors_config', $config['cors'] ?? []); |
47
|
1 |
|
$container->setParameter('graphql.graphiql', $config['graphiql'] ?? []); |
48
|
1 |
|
$container->setParameter('graphql.graphiql_auth_jwt', $config['graphiql']['authentication']['provider']['jwt'] ?? []); |
49
|
1 |
|
$container->setParameter('graphql.security.validation_rules', $config['security']['validation_rules'] ?? []); |
50
|
|
|
|
51
|
1 |
|
$endpointsConfig = []; |
52
|
1 |
|
$endpointsConfig['endpoints'] = $config['endpoints'] ?? []; |
53
|
1 |
|
$endpointsConfig['default'] = $config['endpoint_default'] ?? null; |
54
|
1 |
|
$endpointsConfig['alias'] = $config['endpoint_alias'] ?? []; |
55
|
|
|
|
56
|
1 |
|
$container->setParameter('graphql.endpoints', $endpointsConfig); |
57
|
|
|
|
58
|
1 |
|
$graphiQLAuthProvider = null; |
59
|
1 |
|
if ($config['graphiql']['authentication']['provider']['jwt']['enabled'] ?? false) { |
60
|
1 |
|
$graphiQLAuthProvider = JWTGraphiQLAuthentication::class; |
61
|
|
|
} |
62
|
1 |
|
if ($config['graphiql']['authentication']['provider']['custom'] ?? false) { |
63
|
|
|
$graphiQLAuthProvider = $config['graphiql']['authentication']['provider']['custom']; |
64
|
|
|
} |
65
|
1 |
|
$container->setParameter('graphql.graphiql_auth_provider', $graphiQLAuthProvider); |
66
|
|
|
|
67
|
1 |
|
$configDir = __DIR__.'/../Resources/config'; |
68
|
1 |
|
$loader = new YamlFileLoader($container, new FileLocator($configDir)); |
69
|
1 |
|
$loader->load('services.yml'); |
70
|
|
|
|
71
|
1 |
|
if (!$container->getParameter('kernel.debug')) { |
72
|
1 |
|
$container->getDefinition(DefinitionCacheWarmer::class)->clearTag('kernel.event_subscriber'); |
73
|
|
|
} |
74
|
1 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritDoc} |
78
|
|
|
*/ |
79
|
1 |
|
public function getAlias() |
80
|
|
|
{ |
81
|
1 |
|
return 'graphql'; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|