Psr7Middlewares\Utils\HtmlInjectorTrait::inject PHP Method

inject() private method

Inject some code just before any tag.
private inject ( Psr\Http\Message\ResponseInterface $response, string $code, string $tag = 'body' ) : Psr\Http\Message\ResponseInterface
$response Psr\Http\Message\ResponseInterface
$code string
$tag string
return Psr\Http\Message\ResponseInterface
    private function inject(ResponseInterface $response, $code, $tag = 'body')
    {
        $html = (string) $response->getBody();
        $pos = strripos($html, "</{$tag}>");
        if ($pos === false) {
            $response->getBody()->write($code);
            return $response;
        }
        $body = self::createStream();
        $body->write(substr($html, 0, $pos) . $code . substr($html, $pos));
        return $response->withBody($body);
    }
HtmlInjectorTrait