-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathKernel.php
More file actions
94 lines (81 loc) · 2.71 KB
/
Kernel.php
File metadata and controls
94 lines (81 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/*
* This file is part of the DriftPHP package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <yuhu@mmoreram.com>
*/
declare(strict_types=1);
namespace Drift;
use Drift\HttpKernel\AsyncKernel;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Exception\LoaderLoadException;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Routing\RouteCollectionBuilder;
/**
* Class Kernel.
*/
class Kernel extends AsyncKernel
{
use MicroKernelTrait;
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
/**
* @return iterable
*/
public function registerBundles(): iterable
{
$contents = require $this->getApplicationLayerDir().'/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class($this);
}
}
}
/**
* @return string
*/
public function getProjectDir(): string
{
return \dirname(__DIR__);
}
/**
* @return string
*/
private function getApplicationLayerDir(): string
{
return $this->getProjectDir().'/Drift';
}
/**
* @param ContainerBuilder $container
* @param LoaderInterface $loader
*
* @throws \Exception
*/
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$confDir = $this->getApplicationLayerDir().'/config';
$container->setParameter('container.dumper.inline_class_loader', true);
$container->setParameter('container.dumper.inline_factories', true);
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
}
/**
* @param RouteCollectionBuilder $routes
*
* @throws LoaderLoadException
*/
protected function configureRoutes(RouteCollectionBuilder $routes): void
{
$confDir = $this->getApplicationLayerDir().'/config';
$routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
}
}