/**
* 输出debugBar,只有当页面有</body>标签时有效。
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
$request = $event->getRequest();
if (!$event->isMasterRequest()) {
return;
}
if ($request->isXmlHttpRequest()) {
return;
}
if ($response->isRedirection() || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat()) {
return;
}
$path = null;
if ($this->app['debug_bar.auto_res']) {
$scriptName = $event->getRequest()->server->get('SCRIPT_NAME');
$path = $scriptName . $this->app['debug_bar.path'];
} else {
$path = $this->app['debug_bar.path'];
}
$render = $this->app['debug_bar']->getJavascriptRenderer($path);
ob_start();
echo $render->renderHead();
echo $render->render();
$debugContent = ob_get_contents();
ob_end_clean();
$content = $response->getContent();
if (false === strpos($content, '</body>')) {
$content .= $debugContent;
} else {
$content = str_replace("</body>", $debugContent . '</body>', $content);
}
$event->getResponse()->setContent($content);
}