public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
if ($request->getMethod() === 'POST') {
$parsedBody = $this->parseBody($request->getBody());
if (is_array($parsedBody) && isset($parsedBody[self::PARAM])) {
$requestToSimulate = $parsedBody[self::PARAM];
$deserializedRequest = RequestSerializer::fromString($requestToSimulate);
$request = new ServerRequest($request->getServerParams(), $request->getUploadedFiles(), $deserializedRequest->getUri(), $deserializedRequest->getMethod(), $deserializedRequest->getBody(), $deserializedRequest->getHeaders());
}
}
$requestAsString = RequestSerializer::toString($request);
$responseResult = $next($request, $response);
$responseAsString = ResponseSerializer::toString($responseResult);
$html = sprintf($this->getHtmlTemplate(), self::PARAM, $requestAsString, $responseAsString);
return new HtmlResponse($html);
}