No need to use mb functions here

When mb functions are used and a large response is given the OOM happens as mb functions will use large quantities of memory.
This commit is contained in:
Miha Vrhovnik 2014-04-17 14:50:14 +02:00 committed by Fabien Potencier
parent 5b72e5ab04
commit 4e8ba13874

View File

@ -96,16 +96,8 @@ class WebDebugToolbarListener implements EventSubscriberInterface
*/ */
protected function injectToolbar(Response $response) protected function injectToolbar(Response $response)
{ {
if (function_exists('mb_stripos')) {
$posrFunction = 'mb_strripos';
$substrFunction = 'mb_substr';
} else {
$posrFunction = 'strripos';
$substrFunction = 'substr';
}
$content = $response->getContent(); $content = $response->getContent();
$pos = $posrFunction($content, '</body>'); $pos = strripos($content, '</body>');
if (false !== $pos) { if (false !== $pos) {
$toolbar = "\n".str_replace("\n", '', $this->twig->render( $toolbar = "\n".str_replace("\n", '', $this->twig->render(
@ -115,7 +107,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
'token' => $response->headers->get('X-Debug-Token'), 'token' => $response->headers->get('X-Debug-Token'),
) )
))."\n"; ))."\n";
$content = $substrFunction($content, 0, $pos).$toolbar.$substrFunction($content, $pos); $content = substr($content, 0, $pos).$toolbar.substr($content, $pos);
$response->setContent($content); $response->setContent($content);
} }
} }