Completed
Pull Request — development (#658)
by Thomas
06:41
created

Container::generateContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 1
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace OcLegacy;
4
5
use Symfony\Component\Config\ConfigCache;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
9
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
10
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
11
12
class Container
13
{
14
    public static function get($key)
15
    {
16
        return self::getContainer()->get($key);
17
    }
18
19
    /**
20
     * @return Container
21
     */
22
    private static function getContainer()
23
    {
24
        $containerFile = __DIR__ . '/../../var/cache2/container.php';
25
26
        $containerConfigCache = new ConfigCache(
27
            $containerFile,
28
            false
29
        );
30
31
        if (!$containerConfigCache->isFresh()) {
32
            self::generateContainer($containerConfigCache);
33
        }
34
35
        require_once $containerFile;
36
37
        return new \OcLegacyContainer();
38
    }
39
40
    /**
41
     * @param ConfigCache $containerConfigCache
42
     * @return ContainerBuilder
43
     */
44
    private static function generateContainer(ConfigCache $containerConfigCache)
45
    {
46
        $container = new ContainerBuilder();
47
        $fileLocator = new FileLocator(__DIR__ . '/../../app/config');
48
        $loader = new XmlFileLoader($container, $fileLocator);
49
        $loader->load('services_oc.xml');
50
51
        $loader = new YamlFileLoader($container, $fileLocator);
52
        $loader->load('parameters.yml');
53
54
        $container->compile();
55
56
        $dumper = new PhpDumper($container);
57
        $containerConfigCache->write(
58
            $dumper->dump(['class' => 'OcLegacyContainer']),
59
            $container->getResources()
60
        );
61
    }
62
}
63