Passed
Push — master ( 319fcb...7a107a )
by Rafael
04:41
created

YnloGraphQLExtension::load()   D

Complexity

Conditions 9
Paths 32

Size

Total Lines 44
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 9.0029

Importance

Changes 0
Metric Value
dl 0
loc 44
c 0
b 0
f 0
ccs 29
cts 30
cp 0.9667
rs 4.909
cc 9
eloc 29
nc 32
nop 2
crap 9.0029
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