protected function injectProfiler(ResponseInterface $response, string $token): ResponseInterface
    {
        $content         = (string) $response->getBody();
        $renderedContent = $this->createTemplate($token);

        $pos = \mb_strripos($content, '</body>');

        if ($pos !== false) {
            $stream = $this->streamFactory->createStream(
                \mb_substr($content, 0, $pos) . $renderedContent . \mb_substr($content, $pos)
            );

            // Update the new content and reset the content length
            $response = $response->withoutHeader('content-length');

            return $response->withBody($stream);
        }

        $response->getBody()->write($renderedContent);

        return $response;
    }
protected function injectProfiler(ResponseInterface $response, string $token): ResponseInterface
    {
        $content         = (string) $response->getBody();
        $renderedContent = $this->createTemplate($token);

        $pos = \mb_strripos($content, '</body>');

        if ($pos !== false) {
            $stream = $this->streamFactory->createStream(
                \mb_substr($content, 0, $pos) . $renderedContent . \mb_substr($content, $pos)
            );

            // Update the new content and reset the content length
            $response = $response->withoutHeader('content-length');

            return $response->withBody($stream);
        }

        $response->getBody()->write($renderedContent);

        return $response;
    }
protected function injectProfiler ( ResponseInterface $ response , string $ token ) : ResponseInterface { $ content = ( string ) $ response -> getBody ( ) ; $ renderedContent = $ this -> createTemplate ( $ token ) ; $ pos = \ mb_strripos ( $ content , '</body>' ) ; if ( $ pos !== false ) { $ stream = $ this -> streamFactory -> createStream ( \ mb_substr ( $ content , 0 , $ pos ) . $ renderedContent . \ mb_substr ( $ content , $ pos ) ) ; // Update the new content and reset the content length $ response = $ response -> withoutHeader ( 'content-length' ) ; return $ response -> withBody ( $ stream ) ; } $ response -> getBody ( ) -> write ( $ renderedContent ) ; return $ response ; }
Injects the web debug toolbar into the given Response.

@param \Psr\Http\Message\ResponseInterface $response
@param string                              $token

@return \Psr\Http\Message\ResponseInterface

@see https://github.com/symfony/ProfilerBundle/blob/master/EventListener/WebDebugToolbarListener.php
Injects the web debug toolbar into the given Response .