Projekt

Obecné

Profil

Stáhnout (2.06 KB) Statistiky
| Větev: | Revize:
1 579f9cdd Tomáš Ballák
<?php
2
3
namespace App;
4
5 af43940b Tomáš Ballák
use const PHP_VERSION_ID;
6 579f9cdd Tomáš Ballák
use Symfony\Component\Config\Resource\FileResource;
7 af43940b Tomáš Ballák
use Symfony\Component\Config\Loader\LoaderInterface;
8 579f9cdd Tomáš Ballák
use Symfony\Component\Routing\RouteCollectionBuilder;
9 af43940b Tomáš Ballák
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 579f9cdd Tomáš Ballák
14 af43940b Tomáš Ballák
class Kernel extends BaseKernel {
15 579f9cdd Tomáš Ballák
    use MicroKernelTrait;
16
17
    private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
18
19 af43940b Tomáš Ballák
    public function registerBundles(): iterable {
20 579f9cdd Tomáš Ballák
        $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 af43940b Tomáš Ballák
    public function getProjectDir(): string {
29
        return dirname(__DIR__);
30 579f9cdd Tomáš Ballák
    }
31
32 af43940b Tomáš Ballák
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void {
33 579f9cdd Tomáš Ballák
        $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
34 af43940b Tomáš Ballák
        $container->setParameter('container.dumper.inline_class_loader', PHP_VERSION_ID < 70400 || $this->debug);
35 579f9cdd Tomáš Ballák
        $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 af43940b Tomáš Ballák
    protected function configureRoutes(RouteCollectionBuilder $routes): void {
45 579f9cdd Tomáš Ballák
        $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
}