Completed
Push — master ( 15c856...4ce16e )
by Rafael
05:47
created

YnloGraphQLExtension::load()   D

Complexity

Conditions 9
Paths 32

Size

Total Lines 37
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 9.0051

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 24
cts 25
cp 0.96
rs 4.909
c 0
b 0
f 0
cc 9
eloc 24
nc 32
nop 2
crap 9.0051
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']['extensions']['namespaces']['bundles']['aliases']['GraphQLBundle'])) {
35 1
            $config['definitions']['extensions']['namespaces']['bundles']['aliases']['GraphQLBundle'] = 'AppBundle';
36
        }
37
38 1
        $container->setParameter('graphql.config', $config);
39 1
        if (isset($config['definitions']['extensions'])) {
40 1
            foreach ($config['definitions']['extensions'] as $extension => $extConfig) {
41 1
                $extConfig = isset($extConfig['enabled']) && $extConfig['enabled'] ? $extConfig : [];
42 1
                $container->setParameter('graphql.extension_config.'.$extension, $extConfig ?? []);
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
        $graphiQLAuthProvider = null;
52 1
        if ($config['graphiql']['authentication']['provider']['jwt']['enabled'] ?? false) {
53 1
            $graphiQLAuthProvider = JWTGraphiQLAuthentication::class;
54
        }
55 1
        if ($config['graphiql']['authentication']['provider']['custom'] ?? false) {
56
            $graphiQLAuthProvider = $config['graphiql']['authentication']['provider']['custom'];
57
        }
58 1
        $container->setParameter('graphql.graphiql_auth_provider', $graphiQLAuthProvider);
59
60 1
        $configDir = __DIR__.'/../Resources/config';
61 1
        $loader = new YamlFileLoader($container, new FileLocator($configDir));
62 1
        $loader->load('services.yml');
63
64 1
        if (!$container->getParameter('kernel.debug')) {
65 1
            $container->getDefinition(DefinitionCacheWarmer::class)->clearTag('kernel.event_subscriber');
66
        }
67 1
    }
68
69
    /**
70
     * {@inheritDoc}
71
     */
72 1
    public function getAlias()
73
    {
74 1
        return 'graphql';
75
    }
76
}
77