Completed
Push — master ( f092d3...b95bb4 )
by Philip
25:22
created

Kernel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 6
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerBundles() 0 9 3
A getProjectDir() 0 4 1
1
<?php
2
3
namespace App;
4
5
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
6
use Symfony\Component\Config\Loader\LoaderInterface;
7
use Symfony\Component\Config\Resource\FileResource;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
10
use Symfony\Component\Routing\RouteCollectionBuilder;
11
use function dirname;
12
use const PHP_VERSION_ID;
13
14
class Kernel extends BaseKernel
15
{
16
    use MicroKernelTrait;
17
    private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
18
19
    public function registerBundles(): iterable
20
    {
21
        $contents = require $this->getProjectDir().'/config/bundles.php';
22
        foreach ($contents as $class => $envs) {
23
            if ($envs[$this->environment] ?? $envs['all'] ?? false) {
24
                yield new $class();
25
            }
26
        }
27
    }
28
29
    public function getProjectDir(): string
30
    {
31
        return dirname(__DIR__);
32
    }
33
34
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
35
    {
36
        $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
37
        $container->setParameter(
38
            'container.dumper.inline_class_loader',
39
            PHP_VERSION_ID < 70400 || !ini_get('opcache.preload')
40
        );
41
        $container->setParameter('container.dumper.inline_factories', true);
42
        $confDir = $this->getProjectDir().'/config';
43
44
        $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
45
        $loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
46
        $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
47
        $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
48
    }
49
50
    protected function configureRoutes(RouteCollectionBuilder $routes): void
51
    {
52
        $confDir = $this->getProjectDir().'/config';
53
54
        $routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob');
55
        $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
56
        $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
57
    }
58
}
59