protected function injectToolbar(Response $response)
{
if (function_exists('mb_stripos')) {
$posrFunction = 'mb_strripos';
$substrFunction = 'mb_substr';
} else {
$posrFunction = 'strripos';
$substrFunction = 'substr';
}
$content = $response->getContent();
if (false !== $pos = $posrFunction($content, '</body>')) {
$toolbar = "\n".str_replace("\n", '', $this->templating->render(
'WebProfilerBundle:Profiler:toolbar_js.html.twig',
array('token' => $response->headers->get('X-Debug-Token'))
))."\n";
$content = $substrFunction($content, 0, $pos).$toolbar.$substrFunction($content, $pos);
$response->setContent($content);
}
}