Kernel::configureContainer()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 2
nc 1
nop 2
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
18
    private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
19
20
    public function registerBundles(): iterable
21
    {
22
        $contents = require $this->getProjectDir() . '/config/bundles.php';
23
        foreach ($contents as $class => $envs) {
24
            if ($envs[$this->environment] ?? $envs['all'] ?? false) {
25
                yield new $class();
26
            }
27
        }
28
    }
29
30
    public function getProjectDir(): string
31
    {
32
        return dirname(__DIR__);
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected function prepareContainer(ContainerBuilder $container)
39
    {
40
//        $container->registerExtension(new DdrGitkiAppExtension());
41
        parent::prepareContainer($container);
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
//        $loader->load($this->getProjectDir() . '/config.dist.yaml');
57
//        $localGitkiAppConfigFile = $this->getProjectDir() . '/config.yaml';
58
//        if (file_exists($localGitkiAppConfigFile)) {
59
//            $loader->load($localGitkiAppConfigFile);
60
//        }
61
    }
62
63
    protected function configureRoutes(RouteCollectionBuilder $routes): void
64
    {
65
        $confDir = $this->getProjectDir() . '/config';
66
67
        $routes->import($confDir . '/{routes}/' . $this->environment . '/*' . self::CONFIG_EXTS, '/', 'glob');
68
        $routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
69
        $routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
70
    }
71
}
72