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
|
|
|
/** |
15
|
|
|
* Kernel. |
16
|
|
|
*/ |
17
|
|
|
class Kernel extends BaseKernel |
18
|
|
|
{ |
19
|
|
|
use MicroKernelTrait; |
20
|
|
|
|
21
|
|
|
private const CONFIG_EXTS = '.{php,xml,yaml,yml}'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function registerBundles(): iterable |
27
|
|
|
{ |
28
|
|
|
$contents = require $this->getProjectDir() . '/config/bundles.php'; |
29
|
|
|
|
30
|
|
|
foreach ($contents as $class => $envs) { |
31
|
|
|
if ($envs[$this->environment] ?? $envs['all'] ?? false) { |
32
|
|
|
yield new $class(); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function getProjectDir(): string |
41
|
|
|
{ |
42
|
|
|
return \dirname(__DIR__); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void |
49
|
|
|
{ |
50
|
|
|
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php')); |
51
|
|
|
$container->setParameter('container.dumper.inline_class_loader', true); |
52
|
|
|
$confDir = $this->getProjectDir() . '/config'; |
53
|
|
|
|
54
|
|
|
$loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob'); |
55
|
|
|
$loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob'); |
56
|
|
|
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob'); |
57
|
|
|
$loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes): void |
64
|
|
|
{ |
65
|
|
|
$confDir = $this->getProjectDir() . '/config'; |
66
|
|
|
|
67
|
|
|
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob'); |
68
|
|
|
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob'); |
69
|
|
|
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: