Skip to content
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
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CHANGELOG
* Add `framework.allowed_http_method_override` option
* Initialize `router.request_context`'s `_locale` parameter to `%kernel.default_locale%`
* Deprecate `ConfigBuilderCacheWarmer`, return PHP arrays from your config instead
* Add support for selecting the appropriate error renderer based on the `APP_RUNTIME_MODE` env var

7.3
---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

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

namespace Symfony\Bundle\FrameworkBundle\ErrorHandler\ErrorRenderer;

use Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface;

/**
* @internal
*
* @author Yonel Ceruto <[email protected]>
*/
final class RuntimeModeErrorRendererSelector
{
/**
* @param \Closure(): ErrorRendererInterface $htmlErrorRenderer
* @param \Closure(): ErrorRendererInterface $cliErrorRenderer
*/
public static function select(bool $isWebMode, \Closure $htmlErrorRenderer, \Closure $cliErrorRenderer): ErrorRendererInterface
{
return ($isWebMode ? $htmlErrorRenderer : $cliErrorRenderer)();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Bundle\FrameworkBundle\ErrorHandler\ErrorRenderer\RuntimeModeErrorRendererSelector;
use Symfony\Component\ErrorHandler\ErrorRenderer\CliErrorRenderer;
use Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;

return static function (ContainerConfigurator $container) {
Expand All @@ -32,7 +35,19 @@
service('logger')->nullOnInvalid(),
])

->set('error_handler.error_renderer.cli', CliErrorRenderer::class)

->set('error_handler.error_renderer.default', ErrorRendererInterface::class)
->factory([RuntimeModeErrorRendererSelector::class, 'select'])
->args([
param('kernel.runtime_mode.web'),
service_closure('error_renderer.html'),
service_closure('error_renderer.cli'),
])

->alias('error_renderer.html', 'error_handler.error_renderer.html')
->alias('error_renderer', 'error_renderer.html')
->alias('error_renderer.cli', 'error_handler.error_renderer.cli')
->alias('error_renderer.default', 'error_handler.error_renderer.default')
->alias('error_renderer', 'error_renderer.default')
;
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\SerializerCacheWarmer;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
use Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Symfony\Component\ErrorHandler\ErrorRenderer\SerializerErrorRenderer;
use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor;
Expand Down Expand Up @@ -218,7 +219,10 @@
inline_service()
->factory([SerializerErrorRenderer::class, 'getPreferredFormat'])
->args([service('request_stack')]),
service('error_renderer.html'),
inline_service(ErrorRendererInterface::class)
->factory([\Closure::class, 'fromCallable'])
->args([service('error_renderer.default'), 'render'])
->lazy(),
inline_service()
->factory([HtmlErrorRenderer::class, 'isDebug'])
->args([service('request_stack'), param('kernel.debug')]),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

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

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

class ErrorHandlerWebTestCase extends AbstractWebTestCase
{
public function testHtmlErrorResponseOnCliContext()
{
$client = self::createClient(['test_case' => 'ErrorHandler', 'root_config' => 'config.yml', 'debug' => false]);
$client->request('GET', '/_error/500.html');

self::assertResponseStatusCodeSame(500, $client->getResponse()->getStatusCode());
self::assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent());
self::assertStringContainsString('Oops! An Error Occurred', $client->getResponse()->getContent());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
imports:
- { resource: ../config/default.yml }

parameters:
kernel.runtime_mode.web: true

framework:
serializer:
enabled: true
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 <[email protected]>
*
* 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 [
new FrameworkBundle(),
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
imports:
- { resource: ../config/default.yml }

parameters:
kernel.runtime_mode.web: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_errors:
resource: "@FrameworkBundle/Resources/config/routing/errors.xml"
prefix: /_error
Loading