Completed
Push — next ( 19838d...3cfa04 )
by Thomas
12:22 queued 06:06
created

Container::genereateContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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