8000 [WebProfilerBundle][HttpKernel] Make FileLinkFormatter URL format gen… · symfony/symfony@0221720 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0221720

Browse files
[WebProfilerBundle][HttpKernel] Make FileLinkFormatter URL format generation lazy
1 parent ad30087 commit 0221720

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
namespace Symfony\Bundle\WebProfilerBundle\DependencyInjection;
1313

14+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1415
use Symfony\Component\DependencyInjection\Extension\Extension;
1516
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\DependencyInjection\Reference;
1719
use Symfony\Component\Config\FileLocator;
20+
use Symfony\Component\HttpKernel\Kernel;
1821
use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener;
1922

2023
/**
@@ -53,6 +56,11 @@ public function load(array $configs, ContainerBuilder $container)
5356
$container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
5457
$container->setParameter('web_profiler.debug_toolbar.mode', $config['toolbar'] ? WebDebugToolbarListener::ENABLED : WebDebugToolbarListener::DISABLED);
5558
}
59+
60+
if (Kernel::VERSION_ID >= 30408 || Kernel::VERSION_ID >= 40008) {
61+
$container->getDefinition('debug.file_link_formatter')
62+
->replaceArgument(3, new ServiceClosureArgument(new Reference('debug.file_link_formatter.url_format')));
63+
}
5664
}
5765

5866
/**

src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,14 @@
5656
<argument>%debug.file_link_format%</argument>
5757
<argument type="service" id="request_stack" on-invalid="ignore" />
5858
<argument>%kernel.project_dir%</argument>
59-
<argument type="service">
60-
<service class="string">
61-
<factory function="implode" />
62-
<argument type="collection">
63-
<argument type="service">
64-
<service class="string">
65-
<factory service="router" method="generate" />
66-
<argument>_profiler_open_file</argument>
67-
</service>
68-
</argument>
69-
<argument>?file=%%f&amp;line=%%l#line%%l</argument>
70-
</argument>
71-
</service>
72-
</argument>
59+
<argument>/_profiler/open?file=%%f&amp;line=%%l#line%%l</argument>
60+
</service>
61+
62+
<service id="debug.file_link_formatter.url_format" class="string">
63+
<factory class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter" method="generateUrlFormat" />
64+
<argument type="service" id="router" />
65+
<argument>_profiler_open_file</argument>
66+
<argument>?file=%%f&amp;line=%%l#line%%l</argument>
7367
</service>
7468
</services>
7569
</container>

src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\RequestStack;
16+
use Symfony\Component\Routing\Exception\ExceptionInterface;
17+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1618

1719
/**
1820
* Formats debug file links.
@@ -26,6 +28,9 @@ class FileLinkFormatter implements \Serializable
2628
private $baseDir;
2729
private $urlFormat;
2830

31+
/**
32+
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
33+
*/
2934
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, $baseDir = null, $urlFormat = null)
3035
{
3136
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
@@ -70,12 +75,27 @@ public function unserialize($serialized)
7075
}
7176
}
7277

78+
/**
79+
* @internal
80+
*/
81+
public static function generateUrlFormat(UrlGeneratorInterface $router, $routeName, $queryString)
82+
{
83+
try {
84+
return $router->generate($routeName).$queryString;
85+
} catch (ExceptionInterface $e) {
86+
return null;
87+
}
88+
}
89+
7390
private function getFileLinkFormat()
7491
{
7592
if ($this->fileLinkFormat) {
7693
return $this->fileLinkFormat;
7794
}
7895
if ($this->requestStack && $this->baseDir && $this->urlFormat) {
96+
if ($this->urlFormat instanceof \Closure && !$this->urlFormat = \call_user_func($this->urlFormat)) {
97+
return;
98+
}
7999
$request = $this->requestStack->getMasterRequest();
80100
if ($request instanceof Request) {
81101
return array(

0 commit comments

Comments
 (0)
0