Completed
Pull Request — master (#227)
by Carlos
18:43
created

MailerCompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 20 5
1
<?php
2
3
namespace Liip\MonitorBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\Mailer\MailerInterface;
10
11
/**
12
 * Class MailerCompilerPass.
13
 *
14
 * @author Carlos Dominguez <[email protected]>
15
 */
16
class MailerCompilerPass implements CompilerPassInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function process(ContainerBuilder $container)
22
    {
23
        if (false === $container->hasParameter('liip_monitor.mailer.enabled')) {
24
            return;
25
        }
26
27
        if (false === $container->getParameter('liip_monitor.mailer.enabled')) {
28
            return;
29
        }
30
31
        if (!$container->hasDefinition('mailer')) {
32
            throw new \InvalidArgumentException('To enable mail reporting you have to install the "swiftmailer/swiftmailer" or "symfony/mailer".');
33
        }
34
35
        $definition = $container->getDefinition('mailer');
36
        $filename   = \Swift_Mailer::class !== $definition->getClass() ? 'symfony_mailer.xml' : 'swift_mailer.xml';
37
38
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../../Resources/config'));
39
        $loader->load($filename);
40
    }
41
}
42