[WebProfilerBundle][HttpKernel] Make FileLinkFormatter URL format generation lazy
This commit is contained in:
parent
ad30087264
commit
e074c0550c
@ -11,10 +11,13 @@
|
||||
|
||||
namespace Symfony\Bundle\WebProfilerBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener;
|
||||
|
||||
/**
|
||||
@ -53,6 +56,11 @@ class WebProfilerExtension extends Extension
|
||||
$container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
|
||||
$container->setParameter('web_profiler.debug_toolbar.mode', $config['toolbar'] ? WebDebugToolbarListener::ENABLED : WebDebugToolbarListener::DISABLED);
|
||||
}
|
||||
|
||||
if (Kernel::VERSION_ID >= 30408 || Kernel::VERSION_ID >= 40008) {
|
||||
$container->getDefinition('debug.file_link_formatter')
|
||||
->replaceArgument(3, new ServiceClosureArgument(new Reference('debug.file_link_formatter.url_format')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,20 +56,14 @@
|
||||
<argument>%debug.file_link_format%</argument>
|
||||
<argument type="service" id="request_stack" on-invalid="ignore" />
|
||||
<argument>%kernel.project_dir%</argument>
|
||||
<argument type="service">
|
||||
<service class="string">
|
||||
<factory function="implode" />
|
||||
<argument type="collection">
|
||||
<argument type="service">
|
||||
<service class="string">
|
||||
<factory service="router" method="generate" />
|
||||
<argument>_profiler_open_file</argument>
|
||||
</service>
|
||||
</argument>
|
||||
<argument>?file=%%f&line=%%l#line%%l</argument>
|
||||
</argument>
|
||||
</service>
|
||||
</argument>
|
||||
<argument>/_profiler/open?file=%%f&line=%%l#line%%l</argument>
|
||||
</service>
|
||||
|
||||
<service id="debug.file_link_formatter.url_format" class="string">
|
||||
<factory class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter" method="generateUrlFormat" />
|
||||
<argument type="service" id="router" />
|
||||
<argument>_profiler_open_file</argument>
|
||||
<argument>?file=%%f&line=%%l#line%%l</argument>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
@ -13,6 +13,8 @@ namespace Symfony\Component\HttpKernel\Debug;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Routing\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
/**
|
||||
* Formats debug file links.
|
||||
@ -26,6 +28,9 @@ class FileLinkFormatter implements \Serializable
|
||||
private $baseDir;
|
||||
private $urlFormat;
|
||||
|
||||
/**
|
||||
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
|
||||
*/
|
||||
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, $baseDir = null, $urlFormat = null)
|
||||
{
|
||||
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
|
||||
@ -70,6 +75,18 @@ class FileLinkFormatter implements \Serializable
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function generateUrlFormat(UrlGeneratorInterface $router, $routeName, $queryString)
|
||||
{
|
||||
try {
|
||||
return $router->generate($routeName).$queryString;
|
||||
} catch (ExceptionInterface $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function getFileLinkFormat()
|
||||
{
|
||||
if ($this->fileLinkFormat) {
|
||||
@ -78,6 +95,10 @@ class FileLinkFormatter implements \Serializable
|
||||
if ($this->requestStack && $this->baseDir && $this->urlFormat) {
|
||||
$request = $this->requestStack->getMasterRequest();
|
||||
if ($request instanceof Request) {
|
||||
if ($this->urlFormat instanceof \Closure && !$this->urlFormat = \call_user_func($this->urlFormat)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return array(
|
||||
$request->getSchemeAndHttpHost().$request->getBaseUrl().$this->urlFormat,
|
||||
$this->baseDir.DIRECTORY_SEPARATOR, '',
|
||||
|
Reference in New Issue
Block a user