Completed
Push — master ( fe0da3...fc89d0 )
by WEBEWEB
09:18
created

WBWSMSModeExtension::load()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 3
nc 4
nop 2
1
<?php
2
3
/*
4
 * This file is part of the smsmode-bundle package.
5
 *
6
 * (c) 2019 WEBEWEB
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 WBW\Bundle\SMSModeBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\ConfigurationInterface;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Extension\Extension;
18
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
19
use WBW\Bundle\CoreBundle\DependencyInjection\ConfigurationHelper;
20
21
/**
22
 * sMsmode extension.
23
 *
24
 * @author webeweb <https://github.com/webeweb/>
25
 * @package WBW\Bundle\SMSModeBundle\DependencyInjection
26
 */
27
class WBWSMSModeExtension extends Extension {
28
29
    /**
30
     * Extension alias.
31
     *
32
     * @var string
33
     */
34
    const EXTENSION_ALIAS = "wbw_smsmode";
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    public function getAlias() {
40
        return self::EXTENSION_ALIAS;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function load(array $configs, ContainerBuilder $container) {
47
48
        $fileLocator = new FileLocator(__DIR__ . "/../Resources/config");
49
50
        $serviceLoader = new YamlFileLoader($container, $fileLocator);
51
        $serviceLoader->load("services.yml");
52
53
        /** @var ConfigurationInterface $configuration */
54
        $configuration = $this->getConfiguration($configs, $container);
55
56
        $config = $this->processConfiguration($configuration, $configs);
57
58
        if (true === $config["event_listeners"]) {
59
            $serviceLoader->load("event_listeners.yml");
60
        }
61
62
        if (true === array_key_exists("authentication", $config)) {
63
            ConfigurationHelper::registerContainerParameter($container, $config["authentication"], "smsmode", "access_token");
64
            ConfigurationHelper::registerContainerParameter($container, $config["authentication"], "smsmode", "pseudo");
65
            ConfigurationHelper::registerContainerParameter($container, $config["authentication"], "smsmode", "pass");
66
        }
67
68
        ConfigurationHelper::registerContainerParameter($container, $config, $this->getAlias(), "event_listeners");
69
    }
70
}
71