This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php
Fabien Potencier a6dc10c31a changed templating name notation
Old notation: bundle:section:name.format:renderer (where both format and renderer are optional)
New notation: bundle:section:name.format.renderer (where only format is optional)

Valid new template names: Blog:Post:index.php, Blog:Post:index.xml.php

The new notation is more explicit and put all templating engines on the same level (there is no
more the concept of a "default" templating engine).

Even if the notation changed, the semantic has not. So, the logical template name for the above
examples is still 'index'. So, if you use a database loader for instance, the template
name is 'index' and everything else are options.

Upgrading current applications can be easily done by appending .php to each existing template
name reference (in both controllers and templates), and changing :twig to .twig for Twig templates
(for twig templates, you should also add .twig within templates themselves when referencing
another Twig templates).
2010-09-28 08:33:33 +02:00

59 lines
2.0 KiB
PHP

<?php
namespace Symfony\Bundle\FrameworkBundle\Controller;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Symfony\Component\OutputEscaper\SafeDecorator;
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* ExceptionController.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class ExceptionController extends ContainerAware
{
/**
* Converts an Exception to a Response.
*
* @param FlattenException $exception A FlattenException instance
* @param DebugLoggerInterface $logger A DebugLoggerInterface instance
* @param string $format The format to use for rendering (html, xml, ...)
* @param Boolean $embedded Whether the rendered Response will be embedded or not
*
* @throws \InvalidArgumentException When the exception template does not exist
*/
public function exceptionAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html', $embedded = false)
{
$this->container->get('request')->setRequestFormat($format);
$currentContent = '';
while (false !== $content = ob_get_clean()) {
$currentContent .= $content;
}
$response = $this->container->get('templating')->renderResponse(
'FrameworkBundle:Exception:'.($this->container->get('kernel')->isDebug() ? 'exception.php' : 'error.php'),
array(
'exception' => new SafeDecorator($exception),
'logger' => $logger,
'currentContent' => $currentContent,
'embedded' => $embedded,
)
);
$response->setStatusCode($exception->getStatusCode());
return $response;
}
}