Projekt

Obecné

Profil

Stáhnout (2.06 KB) Statistiky
| Větev: | Revize:
1
<?php
2

    
3
namespace App;
4

    
5
use const PHP_VERSION_ID;
6
use Symfony\Component\Config\Resource\FileResource;
7
use Symfony\Component\Config\Loader\LoaderInterface;
8
use Symfony\Component\Routing\RouteCollectionBuilder;
9
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
10
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use function dirname;
13

    
14
class Kernel extends BaseKernel {
15
    use MicroKernelTrait;
16

    
17
    private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
18

    
19
    public function registerBundles(): iterable {
20
        $contents = require $this->getProjectDir().'/config/bundles.php';
21
        foreach ($contents as $class => $envs) {
22
            if ($envs[$this->environment] ?? $envs['all'] ?? false) {
23
                yield new $class();
24
            }
25
        }
26
    }
27

    
28
    public function getProjectDir(): string {
29
        return dirname(__DIR__);
30
    }
31

    
32
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void {
33
        $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
34
        $container->setParameter('container.dumper.inline_class_loader', PHP_VERSION_ID < 70400 || $this->debug);
35
        $container->setParameter('container.dumper.inline_factories', true);
36
        $confDir = $this->getProjectDir().'/config';
37

    
38
        $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
39
        $loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
40
        $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
41
        $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
42
    }
43

    
44
    protected function configureRoutes(RouteCollectionBuilder $routes): void {
45
        $confDir = $this->getProjectDir().'/config';
46

    
47
        $routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob');
48
        $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
49
        $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
50
    }
51
}
(3-3/4)