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\Encoder\IDEncoderManager; |
20
|
|
|
use Ynlo\GraphQLBundle\GraphiQL\JWTGraphiQLAuthentication; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class YnloGraphQLExtension |
24
|
|
|
*/ |
25
|
|
|
class YnloGraphQLExtension extends Extension |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
31
|
|
|
{ |
32
|
1 |
|
$configuration = new Configuration(); |
33
|
1 |
|
$config = $this->processConfiguration($configuration, $configs); |
34
|
|
|
|
35
|
1 |
|
if (!isset($config['namespaces']['bundles']['aliases']['GraphQLBundle'])) { |
36
|
1 |
|
$config['namespaces']['bundles']['aliases']['GraphQLBundle'] = 'AppBundle'; |
37
|
|
|
} |
38
|
|
|
|
39
|
1 |
|
$container->setParameter('graphql.config', $config); |
40
|
1 |
|
$container->setParameter('graphql.pagination', $config['pagination'] ?? []); |
41
|
1 |
|
$container->setParameter('graphql.namespaces', $config['namespaces'] ?? []); |
42
|
1 |
|
$container->setParameter('graphql.cors_config', $config['cors'] ?? []); |
43
|
1 |
|
$container->setParameter('graphql.graphiql', $config['graphiql'] ?? []); |
44
|
|
|
$container->setParameter('graphql.graphiql_auth_jwt', $config['graphiql']['authentication']['provider']['jwt'] ?? []); |
45
|
|
|
$container->setParameter('graphql.security.validation_rules', $config['security']['validation_rules'] ?? []); |
46
|
|
|
|
47
|
1 |
|
$endpointsConfig = []; |
48
|
1 |
|
$endpointsConfig['endpoints'] = $config['endpoints'] ?? []; |
49
|
1 |
|
$endpointsConfig['default'] = $config['endpoint_default'] ?? null; |
50
|
1 |
|
$endpointsConfig['alias'] = $config['endpoint_alias'] ?? []; |
51
|
|
|
|
52
|
1 |
|
$container->setParameter('graphql.endpoints', $endpointsConfig); |
53
|
1 |
|
$container->setParameter('graphql.endpoints_list', array_keys($endpointsConfig['endpoints'])); |
54
|
1 |
|
|
55
|
1 |
|
$graphiQLAuthProvider = null; |
56
|
|
|
if ($config['graphiql']['authentication']['provider']['jwt']['enabled'] ?? false) { |
57
|
1 |
|
$graphiQLAuthProvider = JWTGraphiQLAuthentication::class; |
58
|
|
|
} |
59
|
1 |
|
if ($config['graphiql']['authentication']['provider']['custom'] ?? false) { |
60
|
1 |
|
$graphiQLAuthProvider = $config['graphiql']['authentication']['provider']['custom']; |
61
|
1 |
|
} |
62
|
|
|
$container->setParameter('graphql.graphiql_auth_provider', $graphiQLAuthProvider); |
63
|
1 |
|
|
64
|
|
|
$configDir = __DIR__.'/../Resources/config'; |
65
|
|
|
$loader = new YamlFileLoader($container, new FileLocator($configDir)); |
66
|
1 |
|
$loader->load('services.yml'); |
67
|
|
|
|
68
|
1 |
|
if ($container->getParameter('kernel.environment') !== 'dev') { |
69
|
1 |
|
$container->getDefinition(DefinitionCacheWarmer::class)->clearTag('kernel.event_subscriber'); |
70
|
1 |
|
} |
71
|
|
|
|
72
|
1 |
|
//build the ID encoder manager with configured encoder |
73
|
1 |
|
$container->getDefinition(IDEncoderManager::class) |
74
|
|
|
->setPublic(true) |
75
|
|
|
->replaceArgument(0, $container->getDefinition($config['id_encoder'])); |
76
|
|
|
} |
77
|
1 |
|
|
78
|
1 |
|
/** |
79
|
1 |
|
* {@inheritDoc} |
80
|
1 |
|
*/ |
81
|
|
|
public function getAlias() |
82
|
|
|
{ |
83
|
|
|
return 'graphql'; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|