-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathKernel.php
109 lines (90 loc) · 3.41 KB
/
Kernel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
declare(strict_types=1);
namespace App;
use Shopsys\FrameworkBundle\Component\Translation\Translator;
use Shopsys\FrameworkBundle\Model\Security\Filesystem\FilemanagerAccess;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use function dirname;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
/**
* @return string
*/
public function getCacheDir(): string
{
return $this->getProjectDir() . '/var/cache/' . $this->environment;
}
/**
* @return string
*/
public function getLogDir(): string
{
return $this->getProjectDir() . '/var/log';
}
/**
* @return string
*/
public function getProjectDir(): string
{
return dirname(__DIR__);
}
public function boot()
{
parent::boot();
$filemanagerAccess = $this->container->get(FilemanagerAccess::class);
FilemanagerAccess::injectSelf($filemanagerAccess);
$translator = $this->container->get('translator');
Translator::injectSelf($translator);
}
/**
* @return iterable
*/
public function registerBundles(): iterable
{
$contents = require $this->getProjectDir() . '/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
}
/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
* @param \Symfony\Component\Config\Loader\LoaderInterface $loader
*/
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
$confDir = $this->getProjectDir() . '/config';
$loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
if (file_exists(__DIR__ . '/../../parameters_monorepo.yaml')) {
$loader->load(__DIR__ . '/../../parameters_monorepo.yaml');
}
if (file_exists($confDir . '/parameters_version.yaml')) {
$loader->load($confDir . '/parameters_version.yaml');
}
if (file_exists($confDir . '/parameters.yaml')) {
$loader->load($confDir . '/parameters.yaml');
}
}
/**
* @param \Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator $routes
*/
protected function configureRoutes(RoutingConfigurator $routes): void
{
$confDir = $this->getProjectDir() . '/config';
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS);
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS);
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS);
}
}