Completed
Push — sf4-again ( 823c77 )
by Asmir
23:16
created

GoetasTwitalExtension::load()   D

Complexity

Conditions 9
Paths 96

Size

Total Lines 38
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 9

Importance

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