Avoid using the app global variable in the profiler templates

This keeps them usable outside the fullstack framework (for instance in
Silex).
This commit is contained in:
Christophe Coevoet 2015-05-29 10:20:13 +02:00
parent 31b5e5c5b1
commit 415c79e0a6
2 changed files with 8 additions and 6 deletions

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\WebProfilerBundle\EventListener; namespace Symfony\Bundle\WebProfilerBundle\EventListener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag; use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
@ -101,7 +102,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
return; return;
} }
$this->injectToolbar($response); $this->injectToolbar($response, $request);
} }
/** /**
@ -109,7 +110,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
* *
* @param Response $response A Response instance * @param Response $response A Response instance
*/ */
protected function injectToolbar(Response $response) protected function injectToolbar(Response $response, Request $request)
{ {
$content = $response->getContent(); $content = $response->getContent();
$pos = strripos($content, '</body>'); $pos = strripos($content, '</body>');
@ -121,6 +122,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
'position' => $this->position, 'position' => $this->position,
'excluded_ajax_paths' => $this->excludedAjaxPaths, 'excluded_ajax_paths' => $this->excludedAjaxPaths,
'token' => $response->headers->get('X-Debug-Token'), 'token' => $response->headers->get('X-Debug-Token'),
'request' => $request,
) )
))."\n"; ))."\n";
$content = substr($content, 0, $pos).$toolbar.substr($content, $pos); $content = substr($content, 0, $pos).$toolbar.substr($content, $pos);

View File

@ -205,12 +205,12 @@
/* prevent logging AJAX calls to static and inline files, like templates */ /* prevent logging AJAX calls to static and inline files, like templates */
var path = url; var path = url;
if (url.substr(0, 1) === '/') { if (url.substr(0, 1) === '/') {
if (0 === url.indexOf('{{ app.request.basePath|e('js') }}')) { if (0 === url.indexOf('{{ request.basePath|e('js') }}')) {
path = url.substr({{ app.request.basePath|length }}); path = url.substr({{ request.basePath|length }});
} }
} }
else if (0 === url.indexOf('{{ (app.request.schemeAndHttpHost ~ app.request.basePath)|e('js') }}')) { else if (0 === url.indexOf('{{ (request.schemeAndHttpHost ~ request.basePath)|e('js') }}')) {
path = url.substr({{ (app.request.schemeAndHttpHost ~ app.request.basePath)|length }}); path = url.substr({{ (request.schemeAndHttpHost ~ request.basePath)|length }});
} }
if (path.substr(0, 1) === '/' && !path.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) { if (path.substr(0, 1) === '/' && !path.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {