Completed
Push — master ( d832ea...65f484 )
by Asmir
14:58 queued 05:00
created

GoetasTwitalExtension::load()   D

Complexity

Conditions 9
Paths 96

Size

Total Lines 39
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 9

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 18
cts 18
cp 1
rs 4.909
c 0
b 0
f 0
cc 9
eloc 22
nc 96
nop 2
crap 9
1
<?php
2
3
namespace Goetas\TwitalBundle\DependencyInjection;
4
5
use Goetas\TwitalBundle\Assetic\DirectoryResourceDefinition;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\DependencyInjection\Reference;
10
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
11
12
/**
13
 *
14
 * @author Asmir Mustafic <[email protected]>
15
 *
16
 */
17
class GoetasTwitalExtension extends Extension
18
{
19
    /**
20
     * {@inheritDoc}
21
     */
22
    public function load(array $configs, ContainerBuilder $container)
23
    {
24
        $configuration = new Configuration();
25 5
        $config = $this->processConfiguration($configuration, $configs);
26
27 5
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
28 5
        $loader->load('twital.xml');
29
30 5
31 5
        $loaderDefinition = $container->getDefinition("twital.loader");
32
        foreach ($config["source_adapters"] as $id => $regs) {
33
            foreach ($regs["pattern"] as $reg) {
34 5
                $loaderDefinition->addMethodCall('addSourceAdapter', array($reg, new Reference($id)));
35 5
            }
36 5
        }
37 5
38
        $bundles = $container->getParameter("kernel.bundles");
39
        if (isset($bundles["AsseticBundle"])) {
40
            $loader->load('assetic.xml');
41 5
        }
42 5
43 1
        if (isset($bundles["JMSTranslationBundle"])) {
44
            $loader->load('jms-translation-bundle.xml');
45
        }
46 5
47 1
        if (!empty($config["full_twig_compatibility"])) {
48 1
            $twitalDefinitioin = $container->getDefinition("twital");
49
            $twitalDefinitioin->addMethodCall('addExtension', array(new Reference('twital.extension.full_twig_compatibility')));
50
        }
51 5
52 1
        if (!class_exists('Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface')) {
53
            $container->removeDefinition('twital.cache_warmer');
54 5
        }
55
56
        if (!interface_exists('Symfony\Component\Templating\EngineInterface')
57
            || !class_exists('Symfony\Bundle\TwigBundle\TwigEngine')) {
58
            $container->removeDefinition('templating.engine.twital');
59
        }
60
    }
61
}
62