Kernel::configureContainer()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 1
nop 2
dl 0
loc 11
rs 10
c 0
b 0
f 0
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\Loader\Configurator\RoutingConfigurator;
13
14
/**
15
 * Class Kernel. Generated by Symfony.
16
 */
17
class Kernel extends BaseKernel
18
{
19
    use MicroKernelTrait;
0 ignored issues
show
Bug introduced by
The trait Symfony\Bundle\Framework...Kernel\MicroKernelTrait requires the property $instanceof which is not provided by App\Kernel.
Loading history...
20
21
    private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
22
23
    public function __construct(string $environment, bool $debug)
24
    {
25
        date_default_timezone_set('UTC');
26
        parent::__construct($environment, $debug);
27
    }
28
29
    public function registerBundles(): iterable
30
    {
31
        $contents = require $this->getProjectDir().'/config/bundles.php';
32
        foreach ($contents as $class => $envs) {
33
            if ($envs[$this->environment] ?? $envs['all'] ?? false) {
34
                yield new $class();
35
            }
36
        }
37
    }
38
39
    public function getProjectDir(): string
40
    {
41
        return \dirname(__DIR__);
42
    }
43
44
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
45
    {
46
        $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
47
        $container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || $this->debug);
48
        $container->setParameter('container.dumper.inline_factories', true);
49
        $confDir = $this->getProjectDir().'/config';
50
51
        $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
52
        $loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
53
        $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
54
        $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
55
    }
56
57
    protected function configureRoutes(RoutingConfigurator $routes): void
58
    {
59
        $routes->import('../config/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS);
60
        $routes->import('../config/{routes}/*'.self::CONFIG_EXTS);
61
62
        if (is_file($this->getProjectDir().'/config/routes.yaml')) {
63
            $routes->import('../config/routes.yaml');
64
        }
65
    }
66
}
67