1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Used for test |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace App; |
8
|
|
|
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
10
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
11
|
|
|
use Symfony\Component\Config\Resource\FileResource; |
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
13
|
|
|
use Symfony\Component\HttpKernel\Kernel as BaseKernel; |
14
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder; |
15
|
|
|
|
16
|
|
|
class Kernel extends BaseKernel |
17
|
|
|
{ |
18
|
|
|
use MicroKernelTrait; |
19
|
|
|
|
20
|
|
|
private const CONFIG_EXTS = '.{php,xml,yaml,yml}'; |
21
|
|
|
|
22
|
|
|
public function registerBundles(): iterable |
23
|
|
|
{ |
24
|
|
|
$contents = require $this->getProjectDir().'/config/bundles.php'; |
25
|
|
|
foreach ($contents as $class => $envs) { |
26
|
|
|
if ($envs[$this->environment] ?? $envs['all'] ?? false) { |
27
|
|
|
yield new $class(); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getProjectDir(): string |
33
|
|
|
{ |
34
|
|
|
return \dirname(__DIR__); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getCacheDir() |
38
|
|
|
{ |
39
|
|
|
return sys_get_temp_dir().'/com.github.piedweb.cms-bundle/tests/var/'.$this->environment.'/cache'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getLogDir() |
43
|
|
|
{ |
44
|
|
|
return sys_get_temp_dir().'/com.github.piedweb.cms-bundle/tests/var/'.$this->environment.'/log'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void |
48
|
|
|
{ |
49
|
|
|
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php')); |
50
|
|
|
$container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || $this->debug); |
51
|
|
|
$container->setParameter('container.dumper.inline_factories', 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
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes): void |
61
|
|
|
{ |
62
|
|
|
$confDir = $this->getProjectDir().'/config'; |
63
|
|
|
|
64
|
|
|
$routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob'); |
65
|
|
|
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob'); |
66
|
|
|
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob'); |
67
|
|
|
} |
68
|
|
|
} |