src/CsrfMiddleware.php
private function injectTokenToResponse(ResponseInterface $response, string $tokenValue): ResponseInterface
    {
        // Check if response is html
        $contentTypes = $response->getHeader('content-type');
        $contentType = reset($contentTypes) ?: '';
        if (strpos($contentType, 'text/html') === false) {
            return $response;
        }

        $content = $response->getBody()->__toString();

        if ($this->protectForms) {
            $content = $this->injectFormHiddenFieldToResponse($content, $tokenValue);
        }

        if ($this->protectJqueryAjax) {
            $content = $this->injectJqueryToResponse($content, $tokenValue);
        }

        return $response->withBody($this->streamFactory->createStream($content));
    }
private function injectTokenToResponse(ResponseInterface $response, string $tokenValue): ResponseInterface
    {
        // Check if response is html
        $contentTypes = $response->getHeader('content-type');
        $contentType = reset($contentTypes) ?: '';
        if (strpos($contentType, 'text/html') === false) {
            return $response;
        }

        $content = $response->getBody()->__toString();

        if ($this->protectForms) {
            $content = $this->injectFormHiddenFieldToResponse($content, $tokenValue);
        }

        if ($this->protectJqueryAjax) {
            $content = $this->injectJqueryToResponse($content, $tokenValue);
        }

        return $response->withBody($this->streamFactory->createStream($content));
    }
private function injectTokenToResponse ( ResponseInterface $ response , string $ tokenValue ) : ResponseInterface { // Check if response is html $ contentTypes = $ response -> getHeader ( 'content-type' ) ; $ contentType = reset ( $ contentTypes ) ? : '' ; if ( strpos ( $ contentType , 'text/html' ) === false ) { return $ response ; } $ content = $ response -> getBody ( ) -> __toString ( ) ; if ( $ this -> protectForms ) { $ content = $ this -> injectFormHiddenFieldToResponse ( $ content , $ tokenValue ) ; } if ( $ this -> protectJqueryAjax ) { $ content = $ this -> injectJqueryToResponse ( $ content , $ tokenValue ) ; } return $ response -> withBody ( $ this -> streamFactory -> createStream ( $ content ) ) ; }
Inject token to response object.

@param ResponseInterface $response the response
@param string $tokenValue token value

@throws RuntimeException

@return ResponseInterface the response
Inject token to response object .