1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace Db3v4l; |
4
|
|
|
|
5
|
|
|
use Db3v4l\DependencyInjection\AddDBConsoleCommandPass; |
6
|
|
|
use Db3v4l\DependencyInjection\Extension; |
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
|
|
|
public function getProjectDir(): string |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
return \dirname(__DIR__); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$container->registerExtension(new Extension()); |
38
|
|
|
|
39
|
|
|
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php')); |
40
|
|
|
$container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || !ini_get('opcache.preload')); |
41
|
|
|
$container->setParameter('container.dumper.inline_factories', true); |
42
|
|
|
$confDir = $this->getProjectDir().'/config'; |
43
|
|
|
|
44
|
|
|
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob'); |
45
|
|
|
$loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob'); |
46
|
|
|
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob'); |
47
|
|
|
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes): void |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$confDir = $this->getProjectDir().'/config'; |
53
|
|
|
|
54
|
|
|
$routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob'); |
55
|
|
|
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob'); |
56
|
|
|
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
|
|
|
|
60
|
|
|
* @param ContainerBuilder $container |
|
|
|
|
61
|
|
|
* Use this method to register compiler passes and manipulate the container during the building process. |
62
|
|
|
*/ |
|
|
|
|
63
|
|
|
protected function build(ContainerBuilder $container) |
64
|
|
|
{ |
65
|
|
|
$container->addCompilerPass(new AddDBConsoleCommandPass()); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|