From 587a2c83ec9d5eed683767768489b3e4a0a26c5d Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 10 Aug 2021 12:02:38 +0300 Subject: [PATCH] feat(endpoints): add basic Endpoints class #565 --- src/flextype/core/Endpoints/Endpoints.php | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/flextype/core/Endpoints/Endpoints.php diff --git a/src/flextype/core/Endpoints/Endpoints.php b/src/flextype/core/Endpoints/Endpoints.php new file mode 100644 index 00000000..734b5e72 --- /dev/null +++ b/src/flextype/core/Endpoints/Endpoints.php @@ -0,0 +1,41 @@ + [ + 'title' => 'Bad Request', + 'message' => 'Validation for this particular item failed', + ], + '401' => [ + 'title' => 'Unauthorized', + 'message' => 'Token is wrong', + ], + '404' => [ + 'title' => 'Not Found', + 'message' => 'Not Found', + ] + ]; + + public function getApiResponse(ResponseInterface $response, array $body = [], int $status = 200): ResponseInterface + { + if (count($body) > 0) { + $response->getBody()->write(serializers()->json()->encode($body)); + } + + $response->withStatus($status); + $response->withHeader('Content-Type', 'application/json;charset=' . registry()->get('flextype.settings.charset')); + return $response; + } +} \ No newline at end of file