[Debug][WebProfilerBundle] Fix setting file link format

This commit is contained in:
Nicolas Grekas 2018-04-27 12:57:32 +02:00
parent 620f90d200
commit a4a1645d44
6 changed files with 14 additions and 5 deletions

View File

@ -181,7 +181,9 @@ class CodeExtension extends AbstractExtension
}
}
$text = "$text at line $line";
if (0 < $line) {
$text .= ' at line '.$line;
}
if (false !== $link = $this->getFileLink($file, $line)) {
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, ENT_COMPAT | ENT_SUBSTITUTE, $this->charset), $text);

View File

@ -61,6 +61,9 @@ class FrameworkBundle extends Bundle
{
public function boot()
{
if (!ini_get('xdebug.file_link_format') && !get_cfg_var('xdebug.file_link_format')) {
ini_set('xdebug.file_link_format', $this->container->getParameter('debug.file_link_format'));
}
ErrorHandler::register(null, false)->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true);
if ($this->container->hasParameter('kernel.trusted_proxies')) {

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\WebProfilerBundle\Controller;
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@ -30,11 +31,12 @@ class ExceptionController
protected $debug;
protected $profiler;
public function __construct(Profiler $profiler = null, Environment $twig, $debug)
public function __construct(Profiler $profiler = null, Environment $twig, $debug, FileLinkFormatter $fileLinkFormat = null)
{
$this->profiler = $profiler;
$this->twig = $twig;
$this->debug = $debug;
$this->fileLinkFormat = $fileLinkFormat;
}
/**
@ -58,7 +60,7 @@ class ExceptionController
$template = $this->getTemplate();
if (!$this->twig->getLoader()->exists($template)) {
$handler = new ExceptionHandler($this->debug, $this->twig->getCharset());
$handler = new ExceptionHandler($this->debug, $this->twig->getCharset(), $this->fileLinkFormat);
return new Response($handler->getContent($exception), 200, array('Content-Type' => 'text/html'));
}
@ -98,7 +100,7 @@ class ExceptionController
$template = $this->getTemplate();
if (!$this->templateExists($template)) {
$handler = new ExceptionHandler($this->debug, $this->twig->getCharset());
$handler = new ExceptionHandler($this->debug, $this->twig->getCharset(), $this->fileLinkFormat);
return new Response($handler->getStylesheet($exception), 200, array('Content-Type' => 'text/css'));
}

View File

@ -27,6 +27,7 @@
<argument type="service" id="profiler" on-invalid="null" />
<argument type="service" id="twig" />
<argument>%kernel.debug%</argument>
<argument type="service" id="debug.file_link_formatter" />
</service>
<service id="web_profiler.csp.handler" class="Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler">

View File

@ -8,7 +8,7 @@
{% block body %}
<div class="header">
<h1>{{ file }} <small>line {{ line }}</small></h1>
<h1>{{ file }}{% if 0 < line %} <small>line {{ line }}</small>{% endif %}</h1>
<a class="doc" href="https://symfony.com/doc/{{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}/reference/configuration/framework.html#ide" rel="help">Open in your IDE?</a>
</div>
<div class="source">

View File

@ -31,6 +31,7 @@ class WebProfilerExtensionTest extends TestCase
public static function assertSaneContainer(Container $container, $message = '', $knownPrivates = array())
{
$errors = array();
$knownPrivates[] = 'debug.file_link_formatter.url_format';
foreach ($container->getServiceIds() as $id) {
if (in_array($id, $knownPrivates, true)) { // to be removed in 4.0
continue;