Passed
Push — master ( 75052b...8ecf83 )
by Dmitri
01:50
created

Kernel   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 8
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App;
6
7
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
8
use Symfony\Component\Config\Loader\LoaderInterface;
9
use Symfony\Component\Config\Resource\FileResource;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
12
use Symfony\Component\Routing\RouteCollectionBuilder;
13
14
class Kernel extends BaseKernel
15
{
16
    use MicroKernelTrait;
17
18
    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
19
20
    public function getCacheDir()
21
    {
22
        return $this->getProjectDir() . '/var/cache/' . $this->environment;
23
    }
24
25
    public function getLogDir()
26
    {
27
        return $this->getProjectDir() . '/var/log';
28
    }
29
30
    public function registerBundles()
31
    {
32
        $contents = require $this->getProjectDir() . '/config/bundles.php';
33
        foreach ($contents as $class => $envs) {
34
            if (isset($envs['all']) || isset($envs[$this->environment])) {
35
                yield new $class();
36
            }
37
        }
38
    }
39
40
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
41
    {
42
        $container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
43
        $container->setParameter('container.autowiring.strict_mode', true);
44
        $container->setParameter('container.dumper.inline_class_loader', true);
45
        $confDir = $this->getProjectDir() . '/config';
46
47
        $loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
48
        $loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
49
        $loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');
50
        $loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
51
    }
52
53
    protected function configureRoutes(RouteCollectionBuilder $routes)
54
    {
55
        $confDir = $this->getProjectDir() . '/config';
56
57
        $routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
58
        $routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
59
        $routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
60
    }
61
}
62