From d2bbe3fc2faebc2f5237984a36b999d05d4b5978 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 10 Aug 2021 14:47:39 +0300 Subject: [PATCH] feat(endpoints): update base Endpoints class #565 --- src/flextype/core/Endpoints/Endpoints.php | 31 +++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/flextype/core/Endpoints/Endpoints.php b/src/flextype/core/Endpoints/Endpoints.php index 2d94687c..fe0568d5 100644 --- a/src/flextype/core/Endpoints/Endpoints.php +++ b/src/flextype/core/Endpoints/Endpoints.php @@ -11,12 +11,16 @@ namespace Flextype\Endpoints; use Psr\Http\Message\ResponseInterface; -class Endpoints +use function count; +use function registry; +use function serializers; + +class Endpoints { /** * Status code messages. - * - * @var array + * + * @var array * @access public */ private array $statusCodeMessages = [ @@ -31,14 +35,14 @@ class Endpoints 404 => [ 'title' => 'Not Found', 'message' => 'Not Found', - ] + ], ]; /** * Get Status Code Message. - * + * * @param int $status Status Code. - * + * * @return array Message. */ public function getStatusCodeMessage(int $status): array @@ -48,21 +52,22 @@ class Endpoints /** * Get API responce - * - * @param ResponseInterface $response PSR7 response. - * @param array $body Response body. - * @param int $status Status code. - * + * + * @param ResponseInterface $response PSR7 response. + * @param array $body Response body. + * @param int $status Status code. + * * @return ResponseInterface Response. */ 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 +}