Completed
Push — master ( 586888...6f962e )
by Paweł
16s
created

SyliusThemeExtension::prepend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\ThemeBundle\DependencyInjection;
13
14
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\Config\Loader\LoaderInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
19
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
20
21
/**
22
 * @author Kamil Kokot <[email protected]>
23
 */
24
final class SyliusThemeExtension extends AbstractResourceExtension implements PrependExtensionInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function load(array $configs, ContainerBuilder $container)
30
    {
31
        $config = $this->processConfiguration(new Configuration(), $configs);
32
33
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/services'));
34
        $loader->load('services.xml');
35
        $loader->load(sprintf('driver/%s.xml', $config['driver']));
36
37
        $this->loadFilesystemConfiguration($container, $loader, $config);
38
39
        $container->setParameter('sylius.interface.theme.class', $config['resources']['theme']['classes']['interface']);
40
        $container->setAlias('sylius.context.theme', $config['context']);
41
42
        $this->registerResources('sylius', $config['driver'], $config['resources'], $container);
43
44
        $container->getDefinition('sylius.repository.theme')->setLazy(true);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function prepend(ContainerBuilder $container)
51
    {
52
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/services'));
53
54
        $this->prependSyliusSettings($container, $loader);
55
    }
56
57
    /**
58
     * @param ContainerBuilder $container
59
     * @param LoaderInterface $loader
60
     * @param array $config
61
     */
62
    private function loadFilesystemConfiguration(ContainerBuilder $container, LoaderInterface $loader, array $config)
63
    {
64
        $loader->load('configuration/filesystem.xml');
65
66
        $container->setAlias('sylius.theme.configuration.loader', 'sylius.theme.configuration.loader.json_file');
67
        $container->setAlias('sylius.theme.configuration.provider', 'sylius.theme.configuration.provider.filesystem');
68
        $container->setParameter('sylius.theme.configuration.filesystem.locations', $config['sources']['filesystem']['locations']);
69
    }
70
71
    /**
72
     * @param ContainerBuilder $container
73
     * @param LoaderInterface $loader
74
     */
75
    private function prependSyliusSettings(ContainerBuilder $container, LoaderInterface $loader)
76
    {
77
        if (!$container->hasExtension('sylius_settings')) {
78
            return;
79
        }
80
81
        $loader->load('integration/settings.xml');
82
    }
83
}
84