17
17
use Symfony \Component \HttpFoundation \Request ;
18
18
use Symfony \Component \HttpFoundation \Response ;
19
19
use Symfony \Component \HttpFoundation \Session \Flash \AutoExpireFlashBag ;
20
+ use Symfony \Component \HttpFoundation \UrlHelper ;
20
21
use Symfony \Component \HttpKernel \DataCollector \DumpDataCollector ;
21
22
use Symfony \Component \HttpKernel \Event \ResponseEvent ;
22
23
use Symfony \Component \HttpKernel \KernelEvents ;
@@ -47,8 +48,9 @@ class WebDebugToolbarListener implements EventSubscriberInterface
47
48
private string $ excludedAjaxPaths ;
48
49
private ?ContentSecurityPolicyHandler $ cspHandler ;
49
50
private ?DumpDataCollector $ dumpDataCollector ;
51
+ private ?UrlHelper $ urlHelper ;
50
52
51
- public function __construct (Environment $ twig , bool $ interceptRedirects = false , int $ mode = self ::ENABLED , UrlGeneratorInterface $ urlGenerator = null , string $ excludedAjaxPaths = '^/bundles|^/_wdt ' , ContentSecurityPolicyHandler $ cspHandler = null , DumpDataCollector $ dumpDataCollector = null )
53
+ public function __construct (Environment $ twig , bool $ interceptRedirects = false , int $ mode = self ::ENABLED , UrlGeneratorInterface $ urlGenerator = null , string $ excludedAjaxPaths = '^/bundles|^/_wdt ' , ContentSecurityPolicyHandler $ cspHandler = null , DumpDataCollector $ dumpDataCollector = null , UrlHelper $ urlHelper = null )
52
54
{
53
55
$ this ->twig = $ twig ;
54
56
$ this ->urlGenerator = $ urlGenerator ;
@@ -57,6 +59,7 @@ public function __construct(Environment $twig, bool $interceptRedirects = false,
57
59
$ this ->excludedAjaxPaths = $ excludedAjaxPaths ;
58
60
$ this ->cspHandler = $ cspHandler ;
59
61
$ this ->dumpDataCollector = $ dumpDataCollector ;
62
+ $ this ->urlHelper = $ urlHelper ;
60
63
}
61
64
62
65
public function isEnabled (): bool
@@ -113,7 +116,12 @@ public function onKernelResponse(ResponseEvent $event): void
113
116
$ session ->getFlashBag ()->setAll ($ session ->getFlashBag ()->peekAll ());
114
117
}
115
118
116
- $ response ->setContent ($ this ->twig ->render ('@WebProfiler/Profiler/toolbar_redirect.html.twig ' , ['location ' => $ response ->headers ->get ('Location ' ), 'host ' => $ request ->getSchemeAndHttpHost ()]));
119
+ $ location = $ response ->headers ->get ('Location ' );
120
+ $ response ->setContent ($ this ->twig ->render ('@WebProfiler/Profiler/toolbar_redirect.html.twig ' , [
121
+ 'location ' => $ location ,
122
+ 'host ' => $ request ->getSchemeAndHttpHost (),
123
+ 'absolute_url ' => $ this ->urlHelper ?->getAbsoluteUrl($ location ),
124
+ ]));
117
125
$ response ->setStatusCode (200 );
118
126
$ response ->headers ->remove ('Location ' );
119
127
}
0 commit comments