response = $this->getResponseFormatter() ->withJsonHeader() ->withStatusCode($statusCode) ->withBody(new SuccessJsonResponse($data)) ->format($this->response); } protected function setErrorJsonResponse( string $errorMessage, int $errorCode = 0, array $data = [], int $statusCode = 400 ): void { $this->response = $this->getResponseFormatter() ->withJsonHeader() ->withStatusCode($statusCode) ->withBody(new ErrorJsonResponse($errorCode, $errorMessage, $data)) ->format($this->response); } protected function getResponseFormatter(): ResponseFormatter { return $this->getServiceLocator()->get(ResponseFormatter::class); } /** * @return ServiceLocatorInterface */ abstract public function getServiceLocator(); }