Passed
Push — master ( 36f9d6...294ad3 )
by Mazarini
10:49
created

Kernel::getProjectDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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
12
class Kernel extends BaseKernel
13
{
14
    use MicroKernelTrait;
15
16
    private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
17
18 4
    public function registerBundles(): iterable
19
    {
20 4
        $contents = require $this->getProjectDir().'/config/bundles.php';
21 4
        foreach ($contents as $class => $envs) {
22 4
            if ($envs[$this->environment] ?? $envs['all'] ?? false) {
23 4
                yield new $class();
24
            }
25
        }
26 4
    }
27
28 4
    public function getProjectDir(): string
29
    {
30 4
        return \dirname(__DIR__);
31
    }
32
33 1
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
34
    {
35 1
        $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
36 1
        $container->setParameter('container.dumper.inline_class_loader', true);
37 1
        $confDir = $this->getProjectDir().'/config';
38
39 1
        $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
40 1
        $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
41 1
        $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
42 1
        $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
43 1
    }
44
45 1
    protected function configureRoutes(RouteCollectionBuilder $routes): void
46
    {
47 1
        $confDir = $this->getProjectDir().'/config';
48
49 1
        $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
50 1
        $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
51 1
        $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
52 1
    }
53
}
54