Completed
Push — 2.1 ( d71b25...b2264f )
by Rafał
08:50
created

Kernel::configureRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 8
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\RouteCollectionBuilder;
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
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
31
    {
32
        $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
33
        $container->setParameter('container.dumper.inline_class_loader', true);
34
        $confDir = $this->getProjectDir().'/config';
35
36
        $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
37
        $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
38
        $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
39
        $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
40
    }
41
42
    protected function configureRoutes(RouteCollectionBuilder $routes): void
43
    {
44
        $confDir = $this->getProjectDir().'/config';
45
46
        $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
47
        $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
48
        $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
49
    }
50
}
51