public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {
        $contentType = $request->getHeaderLine('Content-Type');

        if (!$this->match($contentType)) {
            return $delegate->process($request);
        }

        $rawBody = (string)$request->getBody();
        $parsedBody = json_decode($rawBody, true);

        if (!empty($rawBody) && json_last_error() !== JSON_ERROR_NONE) {
            $statusCode = 400;
            $apiMessage = new HttpStatusCodeApiMessage($statusCode);
            $apiMessage->setCode('invalid-json');
            $apiMessage->setValue('Invalid JSON');
            $apiResponse = $this->newPsrResponseWithTranslatedMessages->__invoke(
                null,
                $statusCode,
                $apiMessage
            );

            return $apiResponse;
        }

        $request = $request
            ->withAttribute('rawBody', $rawBody)
            ->withParsedBody($parsedBody);

        return $delegate->process($request);
    }
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {
        $contentType = $request->getHeaderLine('Content-Type');

        if (!$this->match($contentType)) {
            return $delegate->process($request);
        }

        $rawBody = (string)$request->getBody();
        $parsedBody = json_decode($rawBody, true);

        if (!empty($rawBody) && json_last_error() !== JSON_ERROR_NONE) {
            $statusCode = 400;
            $apiMessage = new HttpStatusCodeApiMessage($statusCode);
            $apiMessage->setCode('invalid-json');
            $apiMessage->setValue('Invalid JSON');
            $apiResponse = $this->newPsrResponseWithTranslatedMessages->__invoke(
                null,
                $statusCode,
                $apiMessage
            );

            return $apiResponse;
        }

        $request = $request
            ->withAttribute('rawBody', $rawBody)
            ->withParsedBody($parsedBody);

        return $delegate->process($request);
    }
public function process ( ServerRequestInterface $ request , DelegateInterface $ delegate ) { $ contentType = $ request -> getHeaderLine ( 'Content-Type' ) ; if ( ! $ this -> match ( $ contentType ) ) { return $ delegate -> process ( $ request ) ; } $ rawBody = ( string ) $ request -> getBody ( ) ; $ parsedBody = json_decode ( $ rawBody , true ) ; if ( ! empty ( $ rawBody ) && json_last_error ( ) !== JSON_ERROR_NONE ) { $ statusCode = 400 ; $ apiMessage = new HttpStatusCodeApiMessage ( $ statusCode ) ; $ apiMessage -> setCode ( 'invalid-json' ) ; $ apiMessage -> setValue ( 'Invalid JSON' ) ; $ apiResponse = $ this -> newPsrResponseWithTranslatedMessages -> __invoke ( null , $ statusCode , $ apiMessage ) ; return $ apiResponse ; } $ request = $ request -> withAttribute ( 'rawBody' , $ rawBody ) -> withParsedBody ( $ parsedBody ) ; return $ delegate -> process ( $ request ) ; }
Adds JSON decoded request body to the request, where appropriate.

@param ServerRequestInterface $request
@param DelegateInterface $delegate
@return ResponseInterface|void
Adds JSON decoded request body to the request where appropriate .