Skip to content

Commit 5d24d65

Browse files
Simplify the default Kernel
1 parent dcfc281 commit 5d24d65

File tree

1 file changed

+10
-36
lines changed

1 file changed

+10
-36
lines changed

symfony/framework-bundle/5.1/src/Kernel.php

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,26 @@
33
namespace App;
44

55
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
6-
use Symfony\Component\Config\Loader\LoaderInterface;
7-
use Symfony\Component\Config\Resource\FileResource;
8-
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
97
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
108
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
119

1210
class Kernel extends BaseKernel
1311
{
1412
use MicroKernelTrait;
1513

16-
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
17-
18-
public function registerBundles(): iterable
14+
protected function configureContainer(ContainerConfigurator $container): void
1915
{
20-
$contents = require $this->getProjectDir().'/config/bundles.php';
21-
foreach ($contents as $class => $envs) {
22-
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
23-
yield new $class();
24-
}
25-
}
16+
$container->import('../config/{packages}/*.yaml');
17+
$container->import('../config/{packages}/'.$this->environment.'/*.yaml');
18+
$container->import('../config/{services}.yaml');
19+
$container->import('../config/{services}_'.$this->environment.'.yaml');
2620
}
2721

28-
public function getProjectDir(): string
22+
protected function configureRoutes(RoutingConfigurator $routes): void
2923
{
30-
return \dirname(__DIR__);
31-
}
32-
33-
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
34-
{
35-
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
36-
$container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400);
37-
$container->setParameter('container.dumper.inline_factories', true);
38-
$confDir = $this->getProjectDir().'/config';
39-
40-
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
41-
$loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
42-
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
43-
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
44-
}
45-
46-
protected function configureRouting(RoutingConfigurator $routes): void
47-
{
48-
$confDir = $this->getProjectDir().'/config';
49-
50-
$routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
51-
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, 'glob');
52-
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, 'glob');
24+
$routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
25+
$routes->import('../config/{routes}/*.yaml');
26+
$routes->import('../config/{routes}.yaml');
5327
}
5428
}

0 commit comments

Comments
 (0)