[FrameworkBundle] removed Container dependency for ExceptionFormatter

This commit is contained in:
Fabien Potencier 2010-08-14 22:39:58 +02:00
parent 917da00763
commit 509bfb8940
2 changed files with 11 additions and 9 deletions

View File

@ -56,7 +56,7 @@ class ExceptionController extends Controller
$code = $exception instanceof HttpException ? $exception->getCode() : 500;
$text = Response::$statusTexts[$code];
$formatter = new ExceptionFormatter($this->container);
$formatter = new ExceptionFormatter($this->container->getParameterBag()->has('debug.file_link_format') ? $this->container->getParameter('debug.file_link_format') : null, $this->container->getParameter('kernel.charset'));
$message = null === $exception->getMessage() ? 'n/a' : $exception->getMessage();
$name = get_class($exception);
$traces = $formatter->getTraces($exception, 'html' === $format ? 'html' : 'text');

View File

@ -20,16 +20,19 @@ use Symfony\Components\DependencyInjection\ContainerInterface;
*/
class ExceptionFormatter
{
protected $container;
protected $fileLinkFormat;
protected $charset;
/**
* Constructor.
*
* @param ContainerInterface $container A Container instance
* @param string $fileLinkFormat The format for links to source files
* @param string $charset The current charset
*/
public function __construct(ContainerInterface $container)
public function __construct($fileLinkFormat, $charset = 'UTF-8')
{
$this->container = $container;
$this->fileLinkFormat = null !== $fileLinkFormat ? $fileLinkFormat : ini_get('xdebug.file_link_format');
$this->charset = $charset;
}
/**
@ -150,9 +153,8 @@ class ExceptionFormatter
$text = $file;
}
$linkFormat = $this->container->getParameterBag()->has('debug.file_link_format') ? $this->container->getParameter('debug.file_link_format') : ini_get('xdebug.file_link_format');
if ('html' === $format && $file && $line && $linkFormat) {
$link = strtr($linkFormat, array('%f' => $file, '%l' => $line));
if ('html' === $format && $file && $line && $this->fileLinkFormat) {
$link = strtr($this->fileLinkFormat, array('%f' => $file, '%l' => $line));
$text = sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', $link, $text);
}
@ -172,6 +174,6 @@ class ExceptionFormatter
return $value;
}
return htmlspecialchars($value, ENT_QUOTES, $this->container->getParameter('kernel.charset'));
return htmlspecialchars($value, ENT_QUOTES, $this->charset);
}
}