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:----WXvdxmwKBSe7d3zxd3Bt+67uBCsqCBkF9wNLEOGGkdZOHR4yNgEkwHYFMPNtzq/Bdz1kyv5Id95Xg1RlPVaqAzcsobNhUlzEdl6seXraMLrc7hHTQouNqBj8bFu/xZgu8kD+estJFosF/Q0eze0uIqjhvoVn3ST8tIa1nDkOELfJepNYmCk0lXUve1/CLFQ61vah50niIyb7BlE330gwKdfjmSbDDXzpL/uw3mgwxbhX4hn7EBf0zL0spDwBCe4aigo2jtL+STQ6Rl15bRyGtX68N63SLkpJWyvIYqpfSyWwsZG6c/QuZ0VaE/C5mP0gZOPiVrdlU70A+rObH5baNk9LiPD8OTh3A+BZL44XMMwYLLAFQuBDykPcoopSisoZhNbGgaFlDxsL7c9aCdTspbttnjGBZt0qL3+JD1170vQLkIJ2o+ievM8R/73uHXeGJDWGUvG3gJQSnSodg3aEE0IJxWm103Kk3ezQalgB5uaHv6papAk3sF4GW+7sZghRzJZcP8ajIqQl18iqB8gueiYWZj93m1KGtnv8MA3BBs3N4ZgpICBUJE0mueh2EhL30lqdddAINhuwuSbbKjmHUxxLU12Tj/Xoxjy2wARTdbwk81GAsBUHRxGJrmktms0YuxexIermIPpiiDEmWKlaFOtIuz3B+zCUmWdI47glyw8=----ATTACHMENT:----NjA3NzIwOTM5MjA0MDQ1MCA2NTA4MDEwOTY0NTgxOTg3IDY3OTEyNTQ1MDk1MDQwMzQ=