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\DependencyInjection\ContainerBuilder; |
10
|
|
|
use Symfony\Component\HttpKernel\Kernel as BaseKernel; |
11
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder; |
12
|
|
|
|
13
|
|
|
class Kernel extends BaseKernel |
14
|
|
|
{ |
15
|
|
|
use MicroKernelTrait; |
16
|
|
|
|
17
|
|
|
public const CONFIG_EXTS = '.{php,xml,yaml,yml}'; |
18
|
|
|
|
19
|
|
|
public function getCacheDir() |
20
|
|
|
{ |
21
|
|
|
return \dirname(__DIR__).'/var/cache/'.$this->getEnvironment(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function getLogDir() |
25
|
|
|
{ |
26
|
|
|
return $this->getProjectDir().'/var/log'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function registerBundles() |
30
|
|
|
{ |
31
|
|
|
$contents = include $this->getProjectDir().'/config/bundles.php'; |
32
|
|
|
foreach ($contents as $class => $envs) { |
33
|
|
|
if (isset($envs['all']) || isset($envs[$this->environment])) { |
34
|
|
|
yield new $class(); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) |
40
|
|
|
{ |
41
|
|
|
$container->setParameter('container.autowiring.strict_mode', true); |
42
|
|
|
$container->setParameter('container.dumper.inline_class_loader', true); |
43
|
|
|
$confDir = $this->getProjectDir().'/config'; |
44
|
|
|
$loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob'); |
45
|
|
|
if (is_dir($confDir.'/packages/'.$this->environment)) { |
46
|
|
|
$loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob'); |
47
|
|
|
} |
48
|
|
|
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob'); |
49
|
|
|
$loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes) |
53
|
|
|
{ |
54
|
|
|
$confDir = $this->getProjectDir().'/config'; |
55
|
|
|
if (is_dir($confDir.'/routes/')) { |
56
|
|
|
$routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob'); |
57
|
|
|
} |
58
|
|
|
if (is_dir($confDir.'/routes/'.$this->environment)) { |
59
|
|
|
$routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); |
60
|
|
|
} |
61
|
|
|
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob'); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: