/
Kernel.php
115 lines (97 loc) · 4.56 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
110
111
112
113
114
115
<?php
declare(strict_types=1);
/*
* This file is part of the Zikula package.
*
* Copyright Zikula - https://ziku.la/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
//use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
//use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Zikula\Bundle\CoreBundle\DynamicConfigDumper;
use Zikula\Bundle\CoreBundle\Helper\PersistedBundleHelper;
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaKernel;
class Kernel extends ZikulaKernel
{
use MicroKernelTrait;
/**
* @var string
*/
private $databaseUrl;
public function __construct(string $environment, bool $debug, string $databaseUrl = '')
{
parent::__construct($environment, $debug);
$this->databaseUrl = $databaseUrl;
}
public function registerBundles(): iterable
{
$bundleHelper = new PersistedBundleHelper($this->databaseUrl);
$bundles = require $this->getProjectDir() . '/config/bundles.php';
$bundleHelper->getPersistedBundles($this, $bundles);
foreach ($bundles as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
}
// could be remove when upgrading Symfony to 5.1.0 (wanted?)
public function getProjectDir(): string
{
return dirname(__DIR__);
}
// use new signature when upgrading Symfony to 5.1.0
//protected function configureContainer(ContainerConfigurator $container): void
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
// remove when upgrading to Symfony 5.1.0
$container->setParameter('kernel.secret', '%env(APP_SECRET)%');
/** use with Symfony 5.1.0
$container->import('../config/{packages}/*.yaml');
$container->import('../config/{packages}/' . $this->environment . '/*.yaml');
$container->import('../config/{services}.yaml');
$container->import('../config/{services}_' . $this->environment . '.yaml');
*/
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', $this->debug);
$container->setParameter('container.dumper.inline_factories', true);
$configDir = $this->getProjectDir() . '/config/';
$loader->load($configDir . '{packages}/*.yaml', 'glob');
$loader->load($configDir . '{packages}/' . $this->environment . '/*.yaml', 'glob');
$loader->load($configDir . '{services}.yaml', 'glob');
$loader->load($configDir . '{services}_' . $this->environment . '.yaml', 'glob');
if (is_readable($configDir . 'services_custom.yaml')) {
$loader->load($configDir . 'services_custom.yaml');
}
if (!is_readable($configDir . DynamicConfigDumper::CONFIG_GENERATED)) {
// There is no generated configuration (yet), load default values.
// This only happens at the very first time Symfony is started.
$loader->load($configDir . DynamicConfigDumper::CONFIG_DEFAULT);
} else {
$loader->load($configDir . DynamicConfigDumper::CONFIG_GENERATED);
if (file_exists($configDir . 'dynamic/generated_' . $this->environment . '.yaml')) {
$loader->load($configDir . 'dynamic/generated_' . $this->environment . '.yaml');
}
}
}
// use new signature when upgrading Symfony to 5.1.0
//protected function configureRoutes(RoutingConfigurator $routes): void
protected function configureRoutes(RouteCollectionBuilder $routes): void
{
$configDir = $this->getProjectDir() . '/config/';
/** use with Symfony 5.1.0
$routes->import($configDir . '{routes}/' . $this->environment . '/*.yaml');
$routes->import($configDir . '{routes}/*.yaml');
$routes->import($configDir . '{routes}.yaml');
*/
$routes->import($configDir . '{routes}/' . $this->environment . '/*.yaml', '/', 'glob');
$routes->import($configDir . '{routes}/*.yaml', '/', 'glob');
$routes->import($configDir . '{routes}.yaml', '/', 'glob');
}
}