1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wulkanowy\BitriseRedirector; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
7
|
|
|
use Symfony\Component\Config\Exception\LoaderLoadException; |
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
|
|
|
public const CONFIG_EXTS = '.{php,xml,yaml,yml}'; |
19
|
|
|
|
20
|
|
|
public function getCacheDir() |
21
|
|
|
{ |
22
|
|
|
return $this->getProjectDir().'/var/cache/'.$this->environment; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getLogDir() |
26
|
|
|
{ |
27
|
|
|
return $this->getProjectDir().'/var/log'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function registerBundles() |
31
|
|
|
{ |
32
|
|
|
$contents = require $this->getProjectDir().'/config/bundles.php'; |
33
|
|
|
foreach ((array) $contents as $class => $envs) { |
34
|
|
|
if (isset($envs['all']) || isset($envs[$this->environment])) { |
35
|
|
|
yield new $class(); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ContainerBuilder $container |
42
|
|
|
* @param LoaderInterface $loader |
43
|
|
|
* |
44
|
|
|
* @throws Exception |
45
|
|
|
*/ |
46
|
|
|
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void |
47
|
|
|
{ |
48
|
|
|
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php')); |
49
|
|
|
// Feel free to remove the "container.autowiring.strict_mode" parameter |
50
|
|
|
// if you are using symfony/dependency-injection 4.0+ as it's the default behavior |
51
|
|
|
$container->setParameter('container.autowiring.strict_mode', true); |
52
|
|
|
$container->setParameter('container.dumper.inline_class_loader', true); |
53
|
|
|
$confDir = $this->getProjectDir().'/config'; |
54
|
|
|
|
55
|
|
|
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob'); |
56
|
|
|
$loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob'); |
57
|
|
|
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob'); |
58
|
|
|
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param RouteCollectionBuilder $routes |
63
|
|
|
* |
64
|
|
|
* @throws LoaderLoadException |
65
|
|
|
*/ |
66
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes): void |
67
|
|
|
{ |
68
|
|
|
$confDir = $this->getProjectDir().'/config'; |
69
|
|
|
|
70
|
|
|
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob'); |
71
|
|
|
$routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); |
72
|
|
|
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob'); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: