Browse Source

build fix for #744

Maurits van der Schee 3 years ago
parent
commit
9fbe671edd
2 changed files with 20 additions and 10 deletions
  1. 10
    5
      api.include.php
  2. 10
    5
      api.php

+ 10
- 5
api.include.php View File

@@ -4555,17 +4555,21 @@ namespace Tqdev\PhpCrudApi\Controller {
4555 4555
 
4556 4556
         public function multi($results): ResponseInterface
4557 4557
         {
4558
-            $document = array();
4558
+            $documents = array();
4559
+            $errors = array();
4559 4560
             $success = true;
4560 4561
             foreach ($results as $i=>$result) {
4561 4562
                 if ($result instanceof \Throwable) {
4562
-                    $document[$i] = ErrorDocument::fromException($result);
4563
+                    $documents[$i] = null;
4564
+                    $errors[$i] = ErrorDocument::fromException($result);
4563 4565
                     $success = false;
4564 4566
                 } else {
4565
-                    $document[$i] = $result;
4567
+                    $documents[$i] = $result;
4568
+                    $errors[$i] = new ErrorDocument(new ErrorCode(0),'',null);
4566 4569
                 }
4567 4570
             }
4568 4571
             $status = $success ? ResponseFactory::OK : ResponseFactory::FAILED_DEPENDENCY;
4572
+            $document = $success ? $documents : $errors;
4569 4573
             $response = ResponseFactory::fromObject($status, $document);
4570 4574
             foreach ($results as $i=>$result) {
4571 4575
                 if ($result instanceof \Throwable) {
@@ -9886,7 +9890,7 @@ namespace Tqdev\PhpCrudApi\Record\Document {
9886 9890
 
9887 9891
         public function jsonSerialize()
9888 9892
         {
9889
-            return array_filter($this->serialize());
9893
+            return array_filter($this->serialize(), function($v) {return $v!==null;});
9890 9894
         }
9891 9895
 
9892 9896
         public static function fromException(\Throwable $exception)
@@ -10062,7 +10066,7 @@ namespace Tqdev\PhpCrudApi\Record {
10062 10066
         const PASSWORD_TOO_SHORT = 1021;
10063 10067
 
10064 10068
         private $values = [
10065
-            9999 => ["%s", ResponseFactory::INTERNAL_SERVER_ERROR],
10069
+            0000 => ["Success", ResponseFactory::OK],
10066 10070
             1000 => ["Route '%s' not found", ResponseFactory::NOT_FOUND],
10067 10071
             1001 => ["Table '%s' not found", ResponseFactory::NOT_FOUND],
10068 10072
             1002 => ["Argument count mismatch in '%s'", ResponseFactory::UNPROCESSABLE_ENTITY],
@@ -10085,6 +10089,7 @@ namespace Tqdev\PhpCrudApi\Record {
10085 10089
             1019 => ["Pagination forbidden", ResponseFactory::FORBIDDEN],
10086 10090
             1020 => ["User '%s' already exists", ResponseFactory::CONFLICT],
10087 10091
             1021 => ["Password too short (<%d characters)", ResponseFactory::UNPROCESSABLE_ENTITY],
10092
+            9999 => ["%s", ResponseFactory::INTERNAL_SERVER_ERROR],
10088 10093
         ];
10089 10094
 
10090 10095
         public function __construct(int $code)

+ 10
- 5
api.php View File

@@ -4555,17 +4555,21 @@ namespace Tqdev\PhpCrudApi\Controller {
4555 4555
 
4556 4556
         public function multi($results): ResponseInterface
4557 4557
         {
4558
-            $document = array();
4558
+            $documents = array();
4559
+            $errors = array();
4559 4560
             $success = true;
4560 4561
             foreach ($results as $i=>$result) {
4561 4562
                 if ($result instanceof \Throwable) {
4562
-                    $document[$i] = ErrorDocument::fromException($result);
4563
+                    $documents[$i] = null;
4564
+                    $errors[$i] = ErrorDocument::fromException($result);
4563 4565
                     $success = false;
4564 4566
                 } else {
4565
-                    $document[$i] = $result;
4567
+                    $documents[$i] = $result;
4568
+                    $errors[$i] = new ErrorDocument(new ErrorCode(0),'',null);
4566 4569
                 }
4567 4570
             }
4568 4571
             $status = $success ? ResponseFactory::OK : ResponseFactory::FAILED_DEPENDENCY;
4572
+            $document = $success ? $documents : $errors;
4569 4573
             $response = ResponseFactory::fromObject($status, $document);
4570 4574
             foreach ($results as $i=>$result) {
4571 4575
                 if ($result instanceof \Throwable) {
@@ -9886,7 +9890,7 @@ namespace Tqdev\PhpCrudApi\Record\Document {
9886 9890
 
9887 9891
         public function jsonSerialize()
9888 9892
         {
9889
-            return array_filter($this->serialize());
9893
+            return array_filter($this->serialize(), function($v) {return $v!==null;});
9890 9894
         }
9891 9895
 
9892 9896
         public static function fromException(\Throwable $exception)
@@ -10062,7 +10066,7 @@ namespace Tqdev\PhpCrudApi\Record {
10062 10066
         const PASSWORD_TOO_SHORT = 1021;
10063 10067
 
10064 10068
         private $values = [
10065
-            9999 => ["%s", ResponseFactory::INTERNAL_SERVER_ERROR],
10069
+            0000 => ["Success", ResponseFactory::OK],
10066 10070
             1000 => ["Route '%s' not found", ResponseFactory::NOT_FOUND],
10067 10071
             1001 => ["Table '%s' not found", ResponseFactory::NOT_FOUND],
10068 10072
             1002 => ["Argument count mismatch in '%s'", ResponseFactory::UNPROCESSABLE_ENTITY],
@@ -10085,6 +10089,7 @@ namespace Tqdev\PhpCrudApi\Record {
10085 10089
             1019 => ["Pagination forbidden", ResponseFactory::FORBIDDEN],
10086 10090
             1020 => ["User '%s' already exists", ResponseFactory::CONFLICT],
10087 10091
             1021 => ["Password too short (<%d characters)", ResponseFactory::UNPROCESSABLE_ENTITY],
10092
+            9999 => ["%s", ResponseFactory::INTERNAL_SERVER_ERROR],
10088 10093
         ];
10089 10094
 
10090 10095
         public function __construct(int $code)

Loading…
Cancel
Save