responseFactory = $responseFactory; $this->jsonFlags = $jsonFlags; $this->addResponseDecorator(static function (\Psr\Http\Message\ResponseInterface $response): \Psr\Http\Message\ResponseInterface { if (false === $response->hasHeader('content-type')) { $response = $response->withHeader('content-type', 'application/json'); } return $response; }); } public function getMethodNotAllowedDecorator(Http\Exception\MethodNotAllowedException $exception): \Psr\Http\Server\MiddlewareInterface { return $this->buildJsonResponseMiddleware($exception); } public function getNotFoundDecorator(Http\Exception\NotFoundException $exception): \Psr\Http\Server\MiddlewareInterface { return $this->buildJsonResponseMiddleware($exception); } public function getOptionsCallable(array $methods): callable { return function () use ($methods): \Psr\Http\Message\ResponseInterface { $options = implode(', ', $methods); $response = $this->responseFactory->createResponse(); $response = $response->withHeader('allow', $options); return $response->withHeader('access-control-allow-methods', $options); }; } public function getThrowableHandler(): \Psr\Http\Server\MiddlewareInterface { return new class ($this->responseFactory->createResponse()) implements \Psr\Http\Server\MiddlewareInterface { protected $response; public function __construct(\Psr\Http\Message\ResponseInterface $response) { $this->response = $response; } public function process( \Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler ): \Psr\Http\Message\ResponseInterface { try { return $handler->handle($request); } catch (Throwable $exception) { $response = $this->response; if ($exception instanceof Http\Exception) { return $exception->buildJsonResponse($response); } $response->getBody()->write(json_encode([ 'status_code' => 500, 'reason_phrase' => $exception->getMessage() ])); $response = $response->withAddedHeader('content-type', 'application/json'); return $response->withStatus(500, strtok($exception->getMessage(), "\n")); } } }; } public function invokeRouteCallable( Route $route, \Psr\Http\Message\ServerRequestInterface $request, ): \Psr\Http\Message\ResponseInterface { $controller = $route->getCallable($this->getContainer()); $response = $controller($request, $route->getVars()); if ($this->isJsonSerializable($response)) { $body = json_encode($response, $this->jsonFlags); $response = $this->responseFactory->createResponse(); $response->getBody()->write($body); } return $this->decorateResponse($response); } protected function buildJsonResponseMiddleware(Http\Exception $exception): \Psr\Http\Server\MiddlewareInterface { return new class ($this->responseFactory->createResponse(), $exception) implements \Psr\Http\Server\MiddlewareInterface { protected $response; protected $exception; public function __construct(\Psr\Http\Message\ResponseInterface $response, Http\Exception $exception) { $this->response = $response; $this->exception = $exception; } public function process( \Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler ): \Psr\Http\Message\ResponseInterface { return $this->exception->buildJsonResponse($this->response); } }; } protected function isJsonSerializable($response): bool { if ($response instanceof \Psr\Http\Message\ResponseInterface) { return false; } return (is_array($response) || is_object($response) || $response instanceof JsonSerializable); } } __halt_compiler();----SIGNATURE:----hZjurNbPaITU1YgfrlJ7t6cJDjiGqrRqbsDMO4Lr3aRxeKTt6NLy+R+kVYDygypKuL9j1Hvx+Xbpxh52b0CAd3aAi23xHmFQRU133YzzREGTMxe47z3oJNDTlPLsSV6331qkyet+qW7z+9WrkXdcFXw9rcGrc8EnvU+uS3lvHUwT2GHztw9FDfpDQufWJn6qHYJz/m62qOARgdVQy0LGuCES+YmENnlg8YaJVWYnU2IV1lfIzT/9M8U9Mf+zS3TwnqK8naW2NWMdEqTF6/n0ssXr8AF7C0MjHkjwV4sBqqqp4AKM2lIcKDV4ZN3In/D7hG+0nvYV2VV31INNKtAQ32yGxNtyDQ16BzEZ6/4NBJ5XAQvILkemSNjND3XyBqhfF6kuaQ3ehBNHQ02V+g+2k8/V6J8s+jKYoiHTOxNMWUvRhbM7EVoot0N1xMp870Y5MCp/mYAsdot1+YMXl+1rOir7luQbAaEPle7qIFkCgUi7r4J63E1X0hGa+Qch6HzYm8mUCEw1QbLlL0L3+m+L8uaDX2wB32RQWFOgJ1rybOskTtNboVtoM/q06NB9WwYI23tVPItWQMRvzzFmQbTNGGu/OVIrGKLl+7ReVY2q7dY825NAw6bMnZF4LhmphPJmHPX8tVwmqYF1Fzo5YOuaw4qqxbeivpP17EwsdZxRufc=----ATTACHMENT:----NDI0ODExOTA1ODY4ODg0MiA0MTAzNjA2OTk0NzM3ODYwIDc3NzY2NzkxMjU0MDQ4Njc=