Skip to content

[FrameworkBundle] Fix Kernel configuration loading #57455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function configureContainer(ContainerConfigurator $container, LoaderInte
$container->import($configDir.'/{packages}/*.{php,yaml}');
$container->import($configDir.'/{packages}/'.$this->environment.'/*.{php,yaml}');

if (is_file($configDir.'/services.yaml')) {
if (is_file($this->getConfigDir().'/services.yaml')) {
$container->import($configDir.'/services.yaml');
$container->import($configDir.'/{services}_'.$this->environment.'.yaml');
} else {
Expand All @@ -79,7 +79,7 @@ private function configureRoutes(RoutingConfigurator $routes): void
$routes->import($configDir.'/{routes}/'.$this->environment.'/*.{php,yaml}');
$routes->import($configDir.'/{routes}/*.{php,yaml}');

if (is_file($configDir.'/routes.yaml')) {
if (is_file($this->getConfigDir().'/routes.yaml')) {
$routes->import($configDir.'/routes.yaml');
} else {
$routes->import($configDir.'/{routes}.php');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

require_once __DIR__.'/default/src/DefaultKernel.php';
require_once __DIR__.'/flex-style/src/FlexStyleMicroKernel.php';

class MicroKernelTraitTest extends TestCase
Expand Down Expand Up @@ -150,6 +151,19 @@ public function testSimpleKernel()

$this->assertSame('Hello World!', $response->getContent());
}

public function testDefaultKernel()
{
$kernel = $this->kernel = new DefaultKernel('test', false);
$kernel->boot();

$this->assertTrue($kernel->getContainer()->has('foo_service'));

$request = Request::create('/');
$response = $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, false);

$this->assertSame('OK', $response->getContent());
}
}

abstract class MinimalKernel extends Kernel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Symfony\Bundle\FrameworkBundle\FrameworkBundle;

return [
FrameworkBundle::class => ['all' => true],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
welcome:
path: /
controller: 'kernel'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
foo_service:
class: stdClass
public: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Tests\Kernel;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel;

class DefaultKernel extends Kernel
{
use MicroKernelTrait;

public function __invoke(): Response
{
return new Response('OK');
}

private string $cacheDir;

public function getCacheDir(): string
{
return $this->cacheDir ??= sys_get_temp_dir().'/sf_default_kernel';
}

public function getLogDir(): string
{
return $this->cacheDir;
}

public function getProjectDir(): string
{
return \dirname(__DIR__);
}
}
Loading