diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index 7a17e7fb10e6a..932308e993cf6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php @@ -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 @@ public function load(array $configs, ContainerBuilder $container) $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'))); + } } /** diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml index f56b1f2f50d1a..7854bc199cb2e 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml @@ -56,20 +56,14 @@ %debug.file_link_format% %kernel.project_dir% - - - - - - - - _profiler_open_file - - - ?file=%%f&line=%%l#line%%l - - - + /_profiler/open?file=%%f&line=%%l#line%%l + + + + + + _profiler_open_file + ?file=%%f&line=%%l#line%%l diff --git a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php index c340d9b67200a..1a72ac7e25853 100644 --- a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php +++ b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php @@ -13,6 +13,8 @@ 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 @@ public function unserialize($serialized) } } + /** + * @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 @@ private function getFileLinkFormat() 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, '',