|
4 | 4 |
|
5 | 5 | namespace Tests\Setono\SyliusRedirectPlugin\Application; |
6 | 6 |
|
7 | | -use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer; |
8 | 7 | use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
9 | | -use Symfony\Component\Config\Loader\LoaderInterface; |
10 | | -use Symfony\Component\Config\Resource\FileResource; |
11 | | -use Symfony\Component\DependencyInjection\ContainerBuilder; |
12 | | -use Symfony\Component\HttpKernel\Bundle\BundleInterface; |
13 | 8 | use Symfony\Component\HttpKernel\Kernel as BaseKernel; |
14 | | -use Symfony\Component\Routing\RouteCollectionBuilder; |
15 | 9 |
|
16 | 10 | final class Kernel extends BaseKernel |
17 | 11 | { |
18 | 12 | use MicroKernelTrait; |
19 | | - |
20 | | - private const CONFIG_EXTS = '.{php,xml,yaml,yml}'; |
21 | | - |
22 | | - public function getCacheDir(): string |
23 | | - { |
24 | | - return $this->getProjectDir() . '/var/cache/' . $this->environment; |
25 | | - } |
26 | | - |
27 | | - public function getLogDir(): string |
28 | | - { |
29 | | - return $this->getProjectDir() . '/var/log'; |
30 | | - } |
31 | | - |
32 | | - public function registerBundles(): iterable |
33 | | - { |
34 | | - foreach ($this->getConfigurationDirectories() as $confDir) { |
35 | | - yield from $this->registerBundlesFromFile($confDir . '/bundles.php'); |
36 | | - } |
37 | | - } |
38 | | - |
39 | | - protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void |
40 | | - { |
41 | | - foreach ($this->getConfigurationDirectories() as $confDir) { |
42 | | - $container->addResource(new FileResource($confDir . '/bundles.php')); |
43 | | - } |
44 | | - |
45 | | - $container->setParameter('container.dumper.inline_class_loader', true); |
46 | | - |
47 | | - foreach ($this->getConfigurationDirectories() as $confDir) { |
48 | | - $this->loadContainerConfiguration($loader, $confDir); |
49 | | - } |
50 | | - } |
51 | | - |
52 | | - protected function configureRoutes(RouteCollectionBuilder $routes): void |
53 | | - { |
54 | | - foreach ($this->getConfigurationDirectories() as $confDir) { |
55 | | - $this->loadRoutesConfiguration($routes, $confDir); |
56 | | - } |
57 | | - } |
58 | | - |
59 | | - protected function getContainerBaseClass(): string |
60 | | - { |
61 | | - if ($this->isTestEnvironment()) { |
62 | | - return MockerContainer::class; |
63 | | - } |
64 | | - |
65 | | - return parent::getContainerBaseClass(); |
66 | | - } |
67 | | - |
68 | | - private function isTestEnvironment(): bool |
69 | | - { |
70 | | - return 0 === strpos($this->getEnvironment(), 'test'); |
71 | | - } |
72 | | - |
73 | | - private function loadContainerConfiguration(LoaderInterface $loader, string $confDir): void |
74 | | - { |
75 | | - $loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob'); |
76 | | - $loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob'); |
77 | | - $loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob'); |
78 | | - $loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob'); |
79 | | - } |
80 | | - |
81 | | - private function loadRoutesConfiguration(RouteCollectionBuilder $routes, string $confDir): void |
82 | | - { |
83 | | - $routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob'); |
84 | | - $routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob'); |
85 | | - $routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob'); |
86 | | - } |
87 | | - |
88 | | - /** |
89 | | - * @return BundleInterface[] |
90 | | - */ |
91 | | - private function registerBundlesFromFile(string $bundlesFile): iterable |
92 | | - { |
93 | | - $contents = require $bundlesFile; |
94 | | - foreach ($contents as $class => $envs) { |
95 | | - if (isset($envs['all']) || isset($envs[$this->environment])) { |
96 | | - yield new $class(); |
97 | | - } |
98 | | - } |
99 | | - } |
100 | | - |
101 | | - /** |
102 | | - * @return string[] |
103 | | - */ |
104 | | - private function getConfigurationDirectories(): iterable |
105 | | - { |
106 | | - yield $this->getProjectDir() . '/config'; |
107 | | - } |
108 | 13 | } |
0 commit comments