Commit
… relies on Twig being enabled This commit also fixes exception pages when Twig is not enabled as a templating engine. Instead of just displaying the raw Twig template as before, we now fallback to the default exception handler introduced some time ago.
- Loading branch information
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?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\TwigBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
|
||
/** | ||
* Registers the Twig exception listener if Twig is registered as a templating engine. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class ExceptionListenerPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (false === $container->hasDefinition('twig')) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return; | ||
} | ||
|
||
// register the exception controller only if Twig is enabled | ||
$engines = $container->getParameter('templating.engines'); | ||
if (!in_array('twig', $engines)) { | ||
$container->removeDefinition('twig.exception_listener'); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% include 'TwigBundle:Exception:error.xml.twig' with { 'exception': exception } %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% include 'TwigBundle:Exception:error.xml.twig' with { 'exception': exception } %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% include 'TwigBundle:Exception:exception.xml.twig' with { 'exception': exception } %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* | ||
{% include 'TwigBundle:Exception:exception.txt.twig' with { 'exception': exception } %} | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* | ||
{% include 'TwigBundle:Exception:exception.txt.twig' with { 'exception': exception } %} | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% include 'TwigBundle:Exception:exception.xml.twig' with { 'exception': exception } %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{% extends 'FrameworkBundle::layout.html.twig' %} | ||
{% extends 'TwigBundle::layout.html.twig' %} | ||
|
||
{% block title %} | ||
{{ exception.message }} ({{ status_code }} {{ status_text }}) | ||
{% endblock %} | ||
|
||
{% block body %} | ||
{% include 'FrameworkBundle:Exception:exception.html.twig' %} | ||
{% include 'TwigBundle:Exception:exception.html.twig' %} | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{% if exception.trace|length %} | ||
{% for trace in exception.trace %} | ||
{% include 'FrameworkBundle:Exception:trace.txt.twig' with { 'trace': trace } only %} | ||
{% include 'TwigBundle:Exception:trace.txt.twig' with { 'trace': trace } only %} | ||
|
||
{% endfor %} | ||
{% endif %} |
3 comments
on commit 3749ad4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit means that exceptions are not handled at all in prod as the exception handler is enabled only in debug mode.
Thus, you need to document that overriding the error page by changing the template only works when you use TwigBundle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already the case before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but exceptions were handled by the exception listener in prod. So only build time exception were not handled in prod, and these one should not happen.
For someone that does not use TwigBundle, a NotFoundHttpException would result in a PHP Fatal Error in prod now.
why checking for
twig
? the relevant service in this compiler pass istwig.exception_listener