From 0c9afdd9084fa7b443f8564955d67d2a295c587e Mon Sep 17 00:00:00 2001 From: Dave M Date: Mon, 30 Oct 2023 15:22:11 +0000 Subject: [PATCH] Working on Api's platform from Ulmus\Api --- src/ApiHandler.php | 38 ++++++++++++++++++++++++++++++++++++++ src/ApiResponseHandler.php | 29 ----------------------------- 2 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 src/ApiHandler.php delete mode 100644 src/ApiResponseHandler.php diff --git a/src/ApiHandler.php b/src/ApiHandler.php new file mode 100644 index 0000000..615f211 --- /dev/null +++ b/src/ApiHandler.php @@ -0,0 +1,38 @@ +getParsedBody(); + + if ($json['message'] ?? false) { + if ( array_key_exists('errors', $json) && null === $json['errors'] ?? null) { +# if ($attribute instanceof \Ulmus\Api\Attribute\Obj\Api\Collection) { +# return []; +# } +# elseif ($attribute instanceof \Ulmus\Api\Attribute\Obj\Api\Read) { +# return null; +# } +# elseif ($attribute instanceof \Ulmus\Api\Attribute\Obj\Api\Create) { +# return false; +# } + } + + throw new \Exception($json['message']); + } + + return JsonResponse::fromResponse($response)->withParsedBody($json); + } +} \ No newline at end of file diff --git a/src/ApiResponseHandler.php b/src/ApiResponseHandler.php deleted file mode 100644 index c6513a7..0000000 --- a/src/ApiResponseHandler.php +++ /dev/null @@ -1,29 +0,0 @@ -render(); - - if ($json['message'] ?? false) { - if ( array_key_exists('errors', $json) && null === $json['errors'] ?? null) { - if ($attribute instanceof \Ulmus\Api\Attribute\Obj\Api\Collection) { - return []; - } - elseif ($attribute instanceof \Ulmus\Api\Attribute\Obj\Api\Read) { - return null; - } - elseif ($attribute instanceof \Ulmus\Api\Attribute\Obj\Api\Create) { - return false; - } - } - - throw new \Exception($json['message']); - } - - return $json; - } -} \ No newline at end of file