Passed
Pull Request — master (#9)
by Vincent
04:45
created

SwiftmailerExtension::getXsdValidationBasePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the MindbazBundle package.
5
 *
6
 * (c) David DELEVOYE <[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 Kozikaza\MindbazBundle\DependencyInjection;
13
14
use Symfony\Bundle\SwiftmailerBundle\DependencyInjection\SwiftmailerExtension as BaseSwiftmailerExtension;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
17
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18
19
/**
20
 * Swiftmailer bridge: declare Mindbaz configuration through Swiftmailer configuration.
21
 *
22
 * @author Vincent Chalamon <[email protected]>
23
 */
24
class SwiftmailerExtension extends Extension
25
{
26
    /**
27
     * @var ExtensionInterface|BaseSwiftmailerExtension
28
     */
29
    protected $extension;
30
31
    /**
32
     * @param ExtensionInterface|BaseSwiftmailerExtension $extension
33
     */
34 2
    public function __construct($extension)
35
    {
36 2
        $this->extension = $extension;
37 2
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getAlias()
43
    {
44
        return $this->extension->getAlias();
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getNamespace()
51
    {
52
        return $this->extension->getNamespace();
53
    }
54
55
    /**
56
     * @return bool|string
57
     */
58
    public function getXsdValidationBasePath()
59
    {
60
        return $this->extension->getXsdValidationBasePath();
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 1
    public function load(array $configs, ContainerBuilder $container)
67
    {
68 1
        foreach ($configs as $key => $config) {
69 1
            if (!isset($config['mailers'])) {
70
                continue;
71
            }
72 1
            foreach ($config['mailers'] as $name => $mailer) {
73
                // It's not a Mindbaz transport
74 1
                if (!isset($mailer['transport']) || 'mindbaz' !== $mailer['transport']) {
75 1
                    continue;
76
                }
77
                // Mindbaz parameters are not set through Swiftmailer configuration
78 1
                if (!array_key_exists('id_site', $mailer) ||
79 1
                    !array_key_exists('username', $mailer) ||
80 1
                    !array_key_exists('password', $mailer) ||
81 1
                    !array_key_exists('campaigns', $mailer)
82 1
                ) {
83 1
                    continue;
84
                }
85
                // Set/erase Mindbaz configuration
86 1
                $container->prependExtensionConfig('mindbaz', [
87
                    'credentials' => [
88 1
                        'idSite'   => $mailer['id_site'],
89 1
                        'login'    => $mailer['username'],
90 1
                        'password' => $mailer['password'],
91 1
                    ],
92 1
                    'campaigns'   => $mailer['campaigns'],
93 1
                ]);
94
                unset(
95 1
                    $configs[$key]['mailers'][$name]['id_site'],
96 1
                    $configs[$key]['mailers'][$name]['username'],
97 1
                    $configs[$key]['mailers'][$name]['password'],
98 1
                    $configs[$key]['mailers'][$name]['campaigns']
99
                );
100 1
            }
101 1
        }
102 1
        $this->extension->load($configs, $container);
103 1
    }
104
}
105