Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e074c05

Browse filesBrowse files
[WebProfilerBundle][HttpKernel] Make FileLinkFormatter URL format generation lazy
1 parent ad30087 commit e074c05
Copy full SHA for e074c05

File tree

Expand file treeCollapse file tree

3 files changed

+37
-14
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+37
-14
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php
+8Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml
+8-14Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php
+21Lines changed: 21 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,6 +75,18 @@ 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) {
@@ -78,6 +95,10 @@ private function getFileLinkFormat()
7895
if ($this->requestStack && $this->baseDir && $this->urlFormat) {
7996
$request = $this->requestStack->getMasterRequest();
8097
if ($request instanceof Request) {
98+
if ($this->urlFormat instanceof \Closure && !$this->urlFormat = \call_user_func($this->urlFormat)) {
99+
return;
100+
}
101+
81102
return array(
82103
$request->getSchemeAndHttpHost().$request->getBaseUrl().$this->urlFormat,
83104
$this->baseDir.DIRECTORY_SEPARATOR, '',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.