Maurits van der Schee 5 years ago
parent
commit
53dc5f36a9
29 changed files with 107 additions and 193 deletions
  1. 2
    1
      src/Tqdev/PhpCrudApi/Api.php
  2. 2
    2
      src/Tqdev/PhpCrudApi/Controller/CacheController.php
  3. 10
    10
      src/Tqdev/PhpCrudApi/Controller/ColumnController.php
  4. 2
    2
      src/Tqdev/PhpCrudApi/Controller/OpenApiController.php
  5. 7
    7
      src/Tqdev/PhpCrudApi/Controller/RecordController.php
  6. 6
    5
      src/Tqdev/PhpCrudApi/Controller/Responder.php
  7. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/AjaxOnlyMiddleware.php
  8. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/AuthorizationMiddleware.php
  9. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/Base/Handler.php
  10. 3
    3
      src/Tqdev/PhpCrudApi/Middleware/BasicAuthMiddleware.php
  11. 11
    10
      src/Tqdev/PhpCrudApi/Middleware/CorsMiddleware.php
  12. 6
    4
      src/Tqdev/PhpCrudApi/Middleware/CustomizationMiddleware.php
  13. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/FirewallMiddleware.php
  14. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/IpAddressMiddleware.php
  15. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/JoinLimitsMiddleware.php
  16. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/JwtAuthMiddleware.php
  17. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/MultiTenancyMiddleware.php
  18. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/PageLimitsMiddleware.php
  19. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/Router/Router.php
  20. 3
    3
      src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php
  21. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/SanitationMiddleware.php
  22. 3
    3
      src/Tqdev/PhpCrudApi/Middleware/ValidationMiddleware.php
  23. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/XsrfMiddleware.php
  24. 22
    22
      src/Tqdev/PhpCrudApi/Record/ErrorCode.php
  25. 0
    93
      src/Tqdev/PhpCrudApi/Response.php
  26. 2
    1
      src/index.php
  27. 2
    1
      test.php
  28. 1
    1
      tests/config/base.php
  29. 1
    1
      tests/functional/001_records/041_cors_pre_flight.log

+ 2
- 1
src/Tqdev/PhpCrudApi/Api.php View File

@@ -1,6 +1,7 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Cache\CacheFactory;
6 7
 use Tqdev\PhpCrudApi\Column\DefinitionService;
@@ -116,7 +117,7 @@ class Api
116 117
         $this->debug = $config->getDebug();
117 118
     }
118 119
 
119
-    public function handle(ServerRequestInterface $request): Response
120
+    public function handle(ServerRequestInterface $request): ResponseInterface
120 121
     {
121 122
         $response = null;
122 123
         try {

+ 2
- 2
src/Tqdev/PhpCrudApi/Controller/CacheController.php View File

@@ -1,10 +1,10 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Controller;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Cache\Cache;
6 7
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
7
-use Tqdev\PhpCrudApi\Response;
8 8
 
9 9
 class CacheController
10 10
 {
@@ -18,7 +18,7 @@ class CacheController
18 18
         $this->responder = $responder;
19 19
     }
20 20
 
21
-    public function clear(ServerRequestInterface $request): Response
21
+    public function clear(ServerRequestInterface $request): ResponseInterface
22 22
     {
23 23
         return $this->responder->success($this->cache->clear());
24 24
     }

+ 10
- 10
src/Tqdev/PhpCrudApi/Controller/ColumnController.php View File

@@ -1,13 +1,13 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Controller;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Column\DefinitionService;
6 7
 use Tqdev\PhpCrudApi\Column\ReflectionService;
7 8
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
8 9
 use Tqdev\PhpCrudApi\Record\ErrorCode;
9 10
 use Tqdev\PhpCrudApi\RequestUtils;
10
-use Tqdev\PhpCrudApi\Response;
11 11
 
12 12
 class ColumnController
13 13
 {
@@ -31,7 +31,7 @@ class ColumnController
31 31
         $this->definition = $definition;
32 32
     }
33 33
 
34
-    public function getDatabase(ServerRequestInterface $request): Response
34
+    public function getDatabase(ServerRequestInterface $request): ResponseInterface
35 35
     {
36 36
         $tables = [];
37 37
         foreach ($this->reflection->getTableNames() as $table) {
@@ -41,7 +41,7 @@ class ColumnController
41 41
         return $this->responder->success($database);
42 42
     }
43 43
 
44
-    public function getTable(ServerRequestInterface $request): Response
44
+    public function getTable(ServerRequestInterface $request): ResponseInterface
45 45
     {
46 46
         $tableName = RequestUtils::getPathSegment($request, 2);
47 47
         if (!$this->reflection->hasTable($tableName)) {
@@ -51,7 +51,7 @@ class ColumnController
51 51
         return $this->responder->success($table);
52 52
     }
53 53
 
54
-    public function getColumn(ServerRequestInterface $request): Response
54
+    public function getColumn(ServerRequestInterface $request): ResponseInterface
55 55
     {
56 56
         $tableName = RequestUtils::getPathSegment($request, 2);
57 57
         $columnName = RequestUtils::getPathSegment($request, 3);
@@ -66,7 +66,7 @@ class ColumnController
66 66
         return $this->responder->success($column);
67 67
     }
68 68
 
69
-    public function updateTable(ServerRequestInterface $request): Response
69
+    public function updateTable(ServerRequestInterface $request): ResponseInterface
70 70
     {
71 71
         $tableName = RequestUtils::getPathSegment($request, 2);
72 72
         if (!$this->reflection->hasTable($tableName)) {
@@ -79,7 +79,7 @@ class ColumnController
79 79
         return $this->responder->success($success);
80 80
     }
81 81
 
82
-    public function updateColumn(ServerRequestInterface $request): Response
82
+    public function updateColumn(ServerRequestInterface $request): ResponseInterface
83 83
     {
84 84
         $tableName = RequestUtils::getPathSegment($request, 2);
85 85
         $columnName = RequestUtils::getPathSegment($request, 3);
@@ -97,7 +97,7 @@ class ColumnController
97 97
         return $this->responder->success($success);
98 98
     }
99 99
 
100
-    public function addTable(ServerRequestInterface $request): Response
100
+    public function addTable(ServerRequestInterface $request): ResponseInterface
101 101
     {
102 102
         $tableName = $request->getParsedBody()->name;
103 103
         if ($this->reflection->hasTable($tableName)) {
@@ -110,7 +110,7 @@ class ColumnController
110 110
         return $this->responder->success($success);
111 111
     }
112 112
 
113
-    public function addColumn(ServerRequestInterface $request): Response
113
+    public function addColumn(ServerRequestInterface $request): ResponseInterface
114 114
     {
115 115
         $tableName = RequestUtils::getPathSegment($request, 2);
116 116
         if (!$this->reflection->hasTable($tableName)) {
@@ -128,7 +128,7 @@ class ColumnController
128 128
         return $this->responder->success($success);
129 129
     }
130 130
 
131
-    public function removeTable(ServerRequestInterface $request): Response
131
+    public function removeTable(ServerRequestInterface $request): ResponseInterface
132 132
     {
133 133
         $tableName = RequestUtils::getPathSegment($request, 2);
134 134
         if (!$this->reflection->hasTable($tableName)) {
@@ -141,7 +141,7 @@ class ColumnController
141 141
         return $this->responder->success($success);
142 142
     }
143 143
 
144
-    public function removeColumn(ServerRequestInterface $request): Response
144
+    public function removeColumn(ServerRequestInterface $request): ResponseInterface
145 145
     {
146 146
         $tableName = RequestUtils::getPathSegment($request, 2);
147 147
         $columnName = RequestUtils::getPathSegment($request, 3);

+ 2
- 2
src/Tqdev/PhpCrudApi/Controller/OpenApiController.php View File

@@ -1,10 +1,10 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Controller;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
6 7
 use Tqdev\PhpCrudApi\OpenApi\OpenApiService;
7
-use Tqdev\PhpCrudApi\Response;
8 8
 
9 9
 class OpenApiController
10 10
 {
@@ -18,7 +18,7 @@ class OpenApiController
18 18
         $this->responder = $responder;
19 19
     }
20 20
 
21
-    public function openapi(ServerRequestInterface $request): Response
21
+    public function openapi(ServerRequestInterface $request): ResponseInterface
22 22
     {
23 23
         return $this->responder->success($this->openApi->get());
24 24
     }

+ 7
- 7
src/Tqdev/PhpCrudApi/Controller/RecordController.php View File

@@ -1,12 +1,12 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Controller;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
6 7
 use Tqdev\PhpCrudApi\Record\ErrorCode;
7 8
 use Tqdev\PhpCrudApi\Record\RecordService;
8 9
 use Tqdev\PhpCrudApi\RequestUtils;
9
-use Tqdev\PhpCrudApi\Response;
10 10
 
11 11
 class RecordController
12 12
 {
@@ -25,7 +25,7 @@ class RecordController
25 25
         $this->responder = $responder;
26 26
     }
27 27
 
28
-    public function _list(ServerRequestInterface $request): Response
28
+    public function _list(ServerRequestInterface $request): ResponseInterface
29 29
     {
30 30
         $table = RequestUtils::getPathSegment($request, 2);
31 31
         $params = RequestUtils::getParams($request);
@@ -35,7 +35,7 @@ class RecordController
35 35
         return $this->responder->success($this->service->_list($table, $params));
36 36
     }
37 37
 
38
-    public function read(ServerRequestInterface $request): Response
38
+    public function read(ServerRequestInterface $request): ResponseInterface
39 39
     {
40 40
         $table = RequestUtils::getPathSegment($request, 2);
41 41
         if (!$this->service->hasTable($table)) {
@@ -62,7 +62,7 @@ class RecordController
62 62
         }
63 63
     }
64 64
 
65
-    public function create(ServerRequestInterface $request): Response
65
+    public function create(ServerRequestInterface $request): ResponseInterface
66 66
     {
67 67
         $table = RequestUtils::getPathSegment($request, 2);
68 68
         if (!$this->service->hasTable($table)) {
@@ -87,7 +87,7 @@ class RecordController
87 87
         }
88 88
     }
89 89
 
90
-    public function update(ServerRequestInterface $request): Response
90
+    public function update(ServerRequestInterface $request): ResponseInterface
91 91
     {
92 92
         $table = RequestUtils::getPathSegment($request, 2);
93 93
         if (!$this->service->hasTable($table)) {
@@ -120,7 +120,7 @@ class RecordController
120 120
         }
121 121
     }
122 122
 
123
-    public function delete(ServerRequestInterface $request): Response
123
+    public function delete(ServerRequestInterface $request): ResponseInterface
124 124
     {
125 125
         $table = RequestUtils::getPathSegment($request, 2);
126 126
         if (!$this->service->hasTable($table)) {
@@ -143,7 +143,7 @@ class RecordController
143 143
         }
144 144
     }
145 145
 
146
-    public function increment(ServerRequestInterface $request): Response
146
+    public function increment(ServerRequestInterface $request): ResponseInterface
147 147
     {
148 148
         $table = RequestUtils::getPathSegment($request, 2);
149 149
         if (!$this->service->hasTable($table)) {

+ 6
- 5
src/Tqdev/PhpCrudApi/Controller/Responder.php View File

@@ -1,23 +1,24 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Controller;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Tqdev\PhpCrudApi\Record\Document\ErrorDocument;
5 6
 use Tqdev\PhpCrudApi\Record\ErrorCode;
6
-use Tqdev\PhpCrudApi\Response;
7
+use Tqdev\PhpCrudApi\ResponseFactory;
7 8
 
8 9
 class Responder
9 10
 {
10
-    public function error(int $error, string $argument, $details = null): Response
11
+    public function error(int $error, string $argument, $details = null): ResponseInterface
11 12
     {
12 13
         $errorCode = new ErrorCode($error);
13 14
         $status = $errorCode->getStatus();
14 15
         $document = new ErrorDocument($errorCode, $argument, $details);
15
-        return new Response($status, $document);
16
+        return ResponseFactory::fromObject($status, $document);
16 17
     }
17 18
 
18
-    public function success($result): Response
19
+    public function success($result): ResponseInterface
19 20
     {
20
-        return new Response(Response::OK, $result);
21
+        return ResponseFactory::fromObject(ResponseFactory::OK, $result);
21 22
     }
22 23
 
23 24
 }

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/AjaxOnlyMiddleware.php View File

@@ -1,16 +1,16 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Controller\Responder;
6 7
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7 8
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8 9
 use Tqdev\PhpCrudApi\RequestUtils;
9
-use Tqdev\PhpCrudApi\Response;
10 10
 
11 11
 class AjaxOnlyMiddleware extends Middleware
12 12
 {
13
-    public function handle(ServerRequestInterface $request): Response
13
+    public function handle(ServerRequestInterface $request): ResponseInterface
14 14
     {
15 15
         $method = $request->getMethod();
16 16
         $excludeMethods = $this->getArrayProperty('excludeMethods', 'OPTIONS,GET');

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/AuthorizationMiddleware.php View File

@@ -1,6 +1,7 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Column\ReflectionService;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
@@ -9,7 +10,6 @@ use Tqdev\PhpCrudApi\Middleware\Communication\VariableStore;
9 10
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10 11
 use Tqdev\PhpCrudApi\Record\FilterInfo;
11 12
 use Tqdev\PhpCrudApi\RequestUtils;
12
-use Tqdev\PhpCrudApi\Response;
13 13
 
14 14
 class AuthorizationMiddleware extends Middleware
15 15
 {
@@ -68,7 +68,7 @@ class AuthorizationMiddleware extends Middleware
68 68
         }
69 69
     }
70 70
 
71
-    public function handle(ServerRequestInterface $request): Response
71
+    public function handle(ServerRequestInterface $request): ResponseInterface
72 72
     {
73 73
         $path = RequestUtils::getPathSegment($request, 1);
74 74
         $operation = RequestUtils::getOperation($request);

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/Base/Handler.php View File

@@ -1,10 +1,10 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware\Base;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5
-use Tqdev\PhpCrudApi\Response;
6 6
 
7 7
 interface Handler
8 8
 {
9
-    public function handle(ServerRequestInterface $request): Response;
9
+    public function handle(ServerRequestInterface $request): ResponseInterface;
10 10
 }

+ 3
- 3
src/Tqdev/PhpCrudApi/Middleware/BasicAuthMiddleware.php View File

@@ -1,12 +1,12 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Controller\Responder;
6 7
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7 8
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8 9
 use Tqdev\PhpCrudApi\RequestUtils;
9
-use Tqdev\PhpCrudApi\Response;
10 10
 
11 11
 class BasicAuthMiddleware extends Middleware
12 12
 {
@@ -75,7 +75,7 @@ class BasicAuthMiddleware extends Middleware
75 75
         return base64_decode(strtr($parts[1], '-_', '+/'));
76 76
     }
77 77
 
78
-    public function handle(ServerRequestInterface $request): Response
78
+    public function handle(ServerRequestInterface $request): ResponseInterface
79 79
     {
80 80
         if (session_status() == PHP_SESSION_NONE) {
81 81
             session_start();
@@ -101,7 +101,7 @@ class BasicAuthMiddleware extends Middleware
101 101
             if ($authenticationMode == 'required') {
102 102
                 $response = $this->responder->error(ErrorCode::AUTHENTICATION_REQUIRED, '');
103 103
                 $realm = $this->getProperty('realm', 'Username and password required');
104
-                $response->addHeader('WWW-Authenticate', "Basic realm=\"$realm\"");
104
+                $response = $response->withHeader('WWW-Authenticate', "Basic realm=\"$realm\"");
105 105
                 return $response;
106 106
             }
107 107
         }

+ 11
- 10
src/Tqdev/PhpCrudApi/Middleware/CorsMiddleware.php View File

@@ -1,11 +1,12 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Controller\Responder;
6 7
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7 8
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8
-use Tqdev\PhpCrudApi\Response;
9
+use Tqdev\PhpCrudApi\ResponseFactory;
9 10
 
10 11
 class CorsMiddleware extends Middleware
11 12
 {
@@ -23,7 +24,7 @@ class CorsMiddleware extends Middleware
23 24
         return $found;
24 25
     }
25 26
 
26
-    public function handle(ServerRequestInterface $request): Response
27
+    public function handle(ServerRequestInterface $request): ResponseInterface
27 28
     {
28 29
         $method = $request->getMethod();
29 30
         $origin = count($request->getHeader('Origin')) ? $request->getHeader('Origin')[0] : '';
@@ -31,26 +32,26 @@ class CorsMiddleware extends Middleware
31 32
         if ($origin && !$this->isOriginAllowed($origin, $allowedOrigins)) {
32 33
             $response = $this->responder->error(ErrorCode::ORIGIN_FORBIDDEN, $origin);
33 34
         } elseif ($method == 'OPTIONS') {
34
-            $response = new Response(Response::OK, '');
35
+            $response = ResponseFactory::fromStatus(ResponseFactory::OK);
35 36
             $allowHeaders = $this->getProperty('allowHeaders', 'Content-Type, X-XSRF-TOKEN, X-Authorization');
36 37
             if ($allowHeaders) {
37
-                $response->addHeader('Access-Control-Allow-Headers', $allowHeaders);
38
+                $response = $response->withHeader('Access-Control-Allow-Headers', $allowHeaders);
38 39
             }
39 40
             $allowMethods = $this->getProperty('allowMethods', 'OPTIONS, GET, PUT, POST, DELETE, PATCH');
40 41
             if ($allowMethods) {
41
-                $response->addHeader('Access-Control-Allow-Methods', $allowMethods);
42
+                $response = $response->withHeader('Access-Control-Allow-Methods', $allowMethods);
42 43
             }
43 44
             $allowCredentials = $this->getProperty('allowCredentials', 'true');
44 45
             if ($allowCredentials) {
45
-                $response->addHeader('Access-Control-Allow-Credentials', $allowCredentials);
46
+                $response = $response->withHeader('Access-Control-Allow-Credentials', $allowCredentials);
46 47
             }
47 48
             $maxAge = $this->getProperty('maxAge', '1728000');
48 49
             if ($maxAge) {
49
-                $response->addHeader('Access-Control-Max-Age', $maxAge);
50
+                $response = $response->withHeader('Access-Control-Max-Age', $maxAge);
50 51
             }
51 52
             $exposeHeaders = $this->getProperty('exposeHeaders', '');
52 53
             if ($exposeHeaders) {
53
-                $response->addHeader('Access-Control-Expose-Headers', $exposeHeaders);
54
+                $response = $response->withHeader('Access-Control-Expose-Headers', $exposeHeaders);
54 55
             }
55 56
         } else {
56 57
             $response = $this->next->handle($request);
@@ -58,9 +59,9 @@ class CorsMiddleware extends Middleware
58 59
         if ($origin) {
59 60
             $allowCredentials = $this->getProperty('allowCredentials', 'true');
60 61
             if ($allowCredentials) {
61
-                $response->addHeader('Access-Control-Allow-Credentials', $allowCredentials);
62
+                $response = $response->withHeader('Access-Control-Allow-Credentials', $allowCredentials);
62 63
             }
63
-            $response->addHeader('Access-Control-Allow-Origin', $origin);
64
+            $response = $response->withHeader('Access-Control-Allow-Origin', $origin);
64 65
         }
65 66
         return $response;
66 67
     }

+ 6
- 4
src/Tqdev/PhpCrudApi/Middleware/CustomizationMiddleware.php View File

@@ -1,13 +1,13 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Column\ReflectionService;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
7 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
9 10
 use Tqdev\PhpCrudApi\RequestUtils;
10
-use Tqdev\PhpCrudApi\Response;
11 11
 
12 12
 class CustomizationMiddleware extends Middleware
13 13
 {
@@ -19,19 +19,21 @@ class CustomizationMiddleware extends Middleware
19 19
         $this->reflection = $reflection;
20 20
     }
21 21
 
22
-    public function handle(ServerRequestInterface $request): Response
22
+    public function handle(ServerRequestInterface $request): ResponseInterface
23 23
     {
24 24
         $operation = RequestUtils::getOperation($request);
25 25
         $tableName = RequestUtils::getPathSegment($request, 2);
26 26
         $beforeHandler = $this->getProperty('beforeHandler', '');
27 27
         $environment = (object) array();
28 28
         if ($beforeHandler !== '') {
29
-            call_user_func($beforeHandler, $operation, $tableName, $request, $environment);
29
+            $result = call_user_func($beforeHandler, $operation, $tableName, $request, $environment);
30
+            $request = $result ?: $request;
30 31
         }
31 32
         $response = $this->next->handle($request);
32 33
         $afterHandler = $this->getProperty('afterHandler', '');
33 34
         if ($afterHandler !== '') {
34
-            call_user_func($afterHandler, $operation, $tableName, $response, $environment);
35
+            $result = call_user_func($afterHandler, $operation, $tableName, $response, $environment);
36
+            $response = $result ?: $response;
35 37
         }
36 38
         return $response;
37 39
     }

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/FirewallMiddleware.php View File

@@ -1,11 +1,11 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Controller\Responder;
6 7
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7 8
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8
-use Tqdev\PhpCrudApi\Response;
9 9
 
10 10
 class FirewallMiddleware extends Middleware
11 11
 {
@@ -34,7 +34,7 @@ class FirewallMiddleware extends Middleware
34 34
         return false;
35 35
     }
36 36
 
37
-    public function handle(ServerRequestInterface $request): Response
37
+    public function handle(ServerRequestInterface $request): ResponseInterface
38 38
     {
39 39
         $reverseProxy = $this->getProperty('reverseProxy', '');
40 40
         if ($reverseProxy) {

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/IpAddressMiddleware.php View File

@@ -1,6 +1,7 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Column\ReflectionService;
6 7
 use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
@@ -8,7 +9,6 @@ use Tqdev\PhpCrudApi\Controller\Responder;
8 9
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
9 10
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10 11
 use Tqdev\PhpCrudApi\RequestUtils;
11
-use Tqdev\PhpCrudApi\Response;
12 12
 
13 13
 class IpAddressMiddleware extends Middleware
14 14
 {
@@ -38,7 +38,7 @@ class IpAddressMiddleware extends Middleware
38 38
         return (object) $context;
39 39
     }
40 40
 
41
-    public function handle(ServerRequestInterface $request): Response
41
+    public function handle(ServerRequestInterface $request): ResponseInterface
42 42
     {
43 43
         $operation = RequestUtils::getOperation($request);
44 44
         if (in_array($operation, ['create', 'update', 'increment'])) {

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/JoinLimitsMiddleware.php View File

@@ -1,6 +1,7 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Column\ReflectionService;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
@@ -8,7 +9,6 @@ use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 9
 use Tqdev\PhpCrudApi\Middleware\Communication\VariableStore;
9 10
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10 11
 use Tqdev\PhpCrudApi\RequestUtils;
11
-use Tqdev\PhpCrudApi\Response;
12 12
 
13 13
 class JoinLimitsMiddleware extends Middleware
14 14
 {
@@ -20,7 +20,7 @@ class JoinLimitsMiddleware extends Middleware
20 20
         $this->reflection = $reflection;
21 21
     }
22 22
 
23
-    public function handle(ServerRequestInterface $request): Response
23
+    public function handle(ServerRequestInterface $request): ResponseInterface
24 24
     {
25 25
         $operation = RequestUtils::getOperation($request);
26 26
         $params = RequestUtils::getParams($request);

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/JwtAuthMiddleware.php View File

@@ -1,12 +1,12 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Controller\Responder;
6 7
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7 8
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8 9
 use Tqdev\PhpCrudApi\RequestUtils;
9
-use Tqdev\PhpCrudApi\Response;
10 10
 
11 11
 class JwtAuthMiddleware extends Middleware
12 12
 {
@@ -121,7 +121,7 @@ class JwtAuthMiddleware extends Middleware
121 121
         return $parts[1];
122 122
     }
123 123
 
124
-    public function handle(ServerRequestInterface $request): Response
124
+    public function handle(ServerRequestInterface $request): ResponseInterface
125 125
     {
126 126
         if (session_status() == PHP_SESSION_NONE) {
127 127
             session_start();

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/MultiTenancyMiddleware.php View File

@@ -1,6 +1,7 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Column\ReflectionService;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
@@ -11,7 +12,6 @@ use Tqdev\PhpCrudApi\Record\Condition\ColumnCondition;
11 12
 use Tqdev\PhpCrudApi\Record\Condition\Condition;
12 13
 use Tqdev\PhpCrudApi\Record\Condition\NoCondition;
13 14
 use Tqdev\PhpCrudApi\RequestUtils;
14
-use Tqdev\PhpCrudApi\Response;
15 15
 
16 16
 class MultiTenancyMiddleware extends Middleware
17 17
 {
@@ -68,7 +68,7 @@ class MultiTenancyMiddleware extends Middleware
68 68
         return $request->withParsedBody($multi ? $records : $records[0]);
69 69
     }
70 70
 
71
-    public function handle(ServerRequestInterface $request): Response
71
+    public function handle(ServerRequestInterface $request): ResponseInterface
72 72
     {
73 73
         $handler = $this->getProperty('handler', '');
74 74
         if ($handler !== '') {

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/PageLimitsMiddleware.php View File

@@ -1,6 +1,7 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Column\ReflectionService;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
@@ -8,7 +9,6 @@ use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
9 10
 use Tqdev\PhpCrudApi\Record\ErrorCode;
10 11
 use Tqdev\PhpCrudApi\RequestUtils;
11
-use Tqdev\PhpCrudApi\Response;
12 12
 
13 13
 class PageLimitsMiddleware extends Middleware
14 14
 {
@@ -20,7 +20,7 @@ class PageLimitsMiddleware extends Middleware
20 20
         $this->reflection = $reflection;
21 21
     }
22 22
 
23
-    public function handle(ServerRequestInterface $request): Response
23
+    public function handle(ServerRequestInterface $request): ResponseInterface
24 24
     {
25 25
         $operation = RequestUtils::getOperation($request);
26 26
         if ($operation == 'list') {

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/Router/Router.php View File

@@ -1,10 +1,10 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware\Router;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Middleware\Base\Handler;
6 7
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7
-use Tqdev\PhpCrudApi\Response;
8 8
 
9 9
 interface Router extends Handler
10 10
 {
@@ -12,5 +12,5 @@ interface Router extends Handler
12 12
 
13 13
     public function load(Middleware $middleware);
14 14
 
15
-    public function route(ServerRequestInterface $request): Response;
15
+    public function route(ServerRequestInterface $request): ResponseInterface;
16 16
 }

+ 3
- 3
src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php View File

@@ -1,13 +1,13 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware\Router;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Cache\Cache;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
7 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 9
 use Tqdev\PhpCrudApi\Record\ErrorCode;
9 10
 use Tqdev\PhpCrudApi\Record\PathTree;
10
-use Tqdev\PhpCrudApi\Response;
11 11
 
12 12
 class SimpleRouter implements Router
13 13
 {
@@ -66,7 +66,7 @@ class SimpleRouter implements Router
66 66
         array_unshift($this->middlewares, $middleware);
67 67
     }
68 68
 
69
-    public function route(ServerRequestInterface $request): Response
69
+    public function route(ServerRequestInterface $request): ResponseInterface
70 70
     {
71 71
         if ($this->registration) {
72 72
             $data = gzcompress(json_encode($this->routes, JSON_UNESCAPED_UNICODE));
@@ -87,7 +87,7 @@ class SimpleRouter implements Router
87 87
         return $this->routes->match($path);
88 88
     }
89 89
 
90
-    public function handle(ServerRequestInterface $request): Response
90
+    public function handle(ServerRequestInterface $request): ResponseInterface
91 91
     {
92 92
         $routeNumbers = $this->getRouteNumbers($request);
93 93
         if (count($routeNumbers) == 0) {

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/SanitationMiddleware.php View File

@@ -1,6 +1,7 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Column\ReflectionService;
6 7
 use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
@@ -8,7 +9,6 @@ use Tqdev\PhpCrudApi\Controller\Responder;
8 9
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
9 10
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10 11
 use Tqdev\PhpCrudApi\RequestUtils;
11
-use Tqdev\PhpCrudApi\Response;
12 12
 
13 13
 class SanitationMiddleware extends Middleware
14 14
 {
@@ -33,7 +33,7 @@ class SanitationMiddleware extends Middleware
33 33
         return (object) $context;
34 34
     }
35 35
 
36
-    public function handle(ServerRequestInterface $request): Response
36
+    public function handle(ServerRequestInterface $request): ResponseInterface
37 37
     {
38 38
         $operation = RequestUtils::getOperation($request);
39 39
         if (in_array($operation, ['create', 'update', 'increment'])) {

+ 3
- 3
src/Tqdev/PhpCrudApi/Middleware/ValidationMiddleware.php View File

@@ -1,6 +1,7 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Column\ReflectionService;
6 7
 use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
@@ -9,7 +10,6 @@ use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
9 10
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10 11
 use Tqdev\PhpCrudApi\Record\ErrorCode;
11 12
 use Tqdev\PhpCrudApi\RequestUtils;
12
-use Tqdev\PhpCrudApi\Response;
13 13
 
14 14
 class ValidationMiddleware extends Middleware
15 15
 {
@@ -21,7 +21,7 @@ class ValidationMiddleware extends Middleware
21 21
         $this->reflection = $reflection;
22 22
     }
23 23
 
24
-    private function callHandler($handler, $record, string $operation, ReflectedTable $table) /*: Response?*/
24
+    private function callHandler($handler, $record, string $operation, ReflectedTable $table) /*: ResponseInterface?*/
25 25
     {
26 26
         $context = (array) $record;
27 27
         $details = array();
@@ -41,7 +41,7 @@ class ValidationMiddleware extends Middleware
41 41
         return null;
42 42
     }
43 43
 
44
-    public function handle(ServerRequestInterface $request): Response
44
+    public function handle(ServerRequestInterface $request): ResponseInterface
45 45
     {
46 46
         $operation = RequestUtils::getOperation($request);
47 47
         if (in_array($operation, ['create', 'update', 'increment'])) {

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/XsrfMiddleware.php View File

@@ -1,11 +1,11 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4
+use Psr\Http\Message\ResponseInterface;
4 5
 use Psr\Http\Message\ServerRequestInterface;
5 6
 use Tqdev\PhpCrudApi\Controller\Responder;
6 7
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7 8
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8
-use Tqdev\PhpCrudApi\Response;
9 9
 
10 10
 class XsrfMiddleware extends Middleware
11 11
 {
@@ -24,7 +24,7 @@ class XsrfMiddleware extends Middleware
24 24
         return $token;
25 25
     }
26 26
 
27
-    public function handle(ServerRequestInterface $request): Response
27
+    public function handle(ServerRequestInterface $request): ResponseInterface
28 28
     {
29 29
         $token = $this->getToken();
30 30
         $method = $request->getMethod();

+ 22
- 22
src/Tqdev/PhpCrudApi/Record/ErrorCode.php View File

@@ -1,7 +1,7 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Record;
3 3
 
4
-use Tqdev\PhpCrudApi\Response;
4
+use Tqdev\PhpCrudApi\ResponseFactory;
5 5
 
6 6
 class ErrorCode
7 7
 {
@@ -33,27 +33,27 @@ class ErrorCode
33 33
     const PAGINATION_FORBIDDEN = 1019;
34 34
 
35 35
     private $values = [
36
-        9999 => ["%s", Response::INTERNAL_SERVER_ERROR],
37
-        1000 => ["Route '%s' not found", Response::NOT_FOUND],
38
-        1001 => ["Table '%s' not found", Response::NOT_FOUND],
39
-        1002 => ["Argument count mismatch in '%s'", Response::UNPROCESSABLE_ENTITY],
40
-        1003 => ["Record '%s' not found", Response::NOT_FOUND],
41
-        1004 => ["Origin '%s' is forbidden", Response::FORBIDDEN],
42
-        1005 => ["Column '%s' not found", Response::NOT_FOUND],
43
-        1006 => ["Table '%s' already exists", Response::CONFLICT],
44
-        1007 => ["Column '%s' already exists", Response::CONFLICT],
45
-        1008 => ["Cannot read HTTP message", Response::UNPROCESSABLE_ENTITY],
46
-        1009 => ["Duplicate key exception", Response::CONFLICT],
47
-        1010 => ["Data integrity violation", Response::CONFLICT],
48
-        1011 => ["Authentication required", Response::UNAUTHORIZED],
49
-        1012 => ["Authentication failed for '%s'", Response::FORBIDDEN],
50
-        1013 => ["Input validation failed for '%s'", Response::UNPROCESSABLE_ENTITY],
51
-        1014 => ["Operation forbidden", Response::FORBIDDEN],
52
-        1015 => ["Operation '%s' not supported", Response::METHOD_NOT_ALLOWED],
53
-        1016 => ["Temporary or permanently blocked", Response::FORBIDDEN],
54
-        1017 => ["Bad or missing XSRF token", Response::FORBIDDEN],
55
-        1018 => ["Only AJAX requests allowed for '%s'", Response::FORBIDDEN],
56
-        1019 => ["Pagination forbidden", Response::FORBIDDEN],
36
+        9999 => ["%s", ResponseFactory::INTERNAL_SERVER_ERROR],
37
+        1000 => ["Route '%s' not found", ResponseFactory::NOT_FOUND],
38
+        1001 => ["Table '%s' not found", ResponseFactory::NOT_FOUND],
39
+        1002 => ["Argument count mismatch in '%s'", ResponseFactory::UNPROCESSABLE_ENTITY],
40
+        1003 => ["Record '%s' not found", ResponseFactory::NOT_FOUND],
41
+        1004 => ["Origin '%s' is forbidden", ResponseFactory::FORBIDDEN],
42
+        1005 => ["Column '%s' not found", ResponseFactory::NOT_FOUND],
43
+        1006 => ["Table '%s' already exists", ResponseFactory::CONFLICT],
44
+        1007 => ["Column '%s' already exists", ResponseFactory::CONFLICT],
45
+        1008 => ["Cannot read HTTP message", ResponseFactory::UNPROCESSABLE_ENTITY],
46
+        1009 => ["Duplicate key exception", ResponseFactory::CONFLICT],
47
+        1010 => ["Data integrity violation", ResponseFactory::CONFLICT],
48
+        1011 => ["Authentication required", ResponseFactory::UNAUTHORIZED],
49
+        1012 => ["Authentication failed for '%s'", ResponseFactory::FORBIDDEN],
50
+        1013 => ["Input validation failed for '%s'", ResponseFactory::UNPROCESSABLE_ENTITY],
51
+        1014 => ["Operation forbidden", ResponseFactory::FORBIDDEN],
52
+        1015 => ["Operation '%s' not supported", ResponseFactory::METHOD_NOT_ALLOWED],
53
+        1016 => ["Temporary or permanently blocked", ResponseFactory::FORBIDDEN],
54
+        1017 => ["Bad or missing XSRF token", ResponseFactory::FORBIDDEN],
55
+        1018 => ["Only AJAX requests allowed for '%s'", ResponseFactory::FORBIDDEN],
56
+        1019 => ["Pagination forbidden", ResponseFactory::FORBIDDEN],
57 57
     ];
58 58
 
59 59
     public function __construct(int $code)

+ 0
- 93
src/Tqdev/PhpCrudApi/Response.php View File

@@ -1,93 +0,0 @@
1
-<?php
2
-namespace Tqdev\PhpCrudApi;
3
-
4
-class Response
5
-{
6
-    const OK = 200;
7
-    const UNAUTHORIZED = 401;
8
-    const FORBIDDEN = 403;
9
-    const NOT_FOUND = 404;
10
-    const METHOD_NOT_ALLOWED = 405;
11
-    const CONFLICT = 409;
12
-    const UNPROCESSABLE_ENTITY = 422;
13
-    const INTERNAL_SERVER_ERROR = 500;
14
-    private $status;
15
-    private $headers;
16
-    private $body;
17
-
18
-    public function __construct(int $status, $body)
19
-    {
20
-        $this->status = $status;
21
-        $this->headers = array();
22
-        $this->parseBody($body);
23
-    }
24
-
25
-    private function parseBody($body)
26
-    {
27
-        if ($body === '') {
28
-            $this->body = '';
29
-        } else {
30
-            $data = json_encode($body, JSON_UNESCAPED_UNICODE);
31
-            $this->addHeader('Content-Type', 'application/json');
32
-            $this->addHeader('Content-Length', strlen($data));
33
-            $this->body = $data;
34
-        }
35
-    }
36
-
37
-    public function getStatus(): int
38
-    {
39
-        return $this->status;
40
-    }
41
-
42
-    public function getBody(): string
43
-    {
44
-        return $this->body;
45
-    }
46
-
47
-    public function addHeader(string $key, string $value)
48
-    {
49
-        $this->headers[$key] = $value;
50
-    }
51
-
52
-    public function getHeader(string $key): string
53
-    {
54
-        if (isset($this->headers[$key])) {
55
-            return $this->headers[$key];
56
-        }
57
-        return null;
58
-    }
59
-
60
-    public function getHeaders(): array
61
-    {
62
-        return $this->headers;
63
-    }
64
-
65
-    public function output()
66
-    {
67
-        http_response_code($this->getStatus());
68
-        foreach ($this->headers as $key => $value) {
69
-            header("$key: $value");
70
-        }
71
-        echo $this->getBody();
72
-    }
73
-
74
-    public function addExceptionHeaders(\Throwable $e)
75
-    {
76
-        $this->addHeader('X-Exception-Name', get_class($e));
77
-        $this->addHeader('X-Exception-Message', $e->getMessage());
78
-        $this->addHeader('X-Exception-File', $e->getFile() . ':' . $e->getLine());
79
-    }
80
-
81
-    public function __toString(): string
82
-    {
83
-        $str = "$this->status\n";
84
-        foreach ($this->headers as $key => $value) {
85
-            $str .= "$key: $value\n";
86
-        }
87
-        if ($this->body !== '') {
88
-            $str .= "\n";
89
-            $str .= "$this->body\n";
90
-        }
91
-        return $str;
92
-    }
93
-}

+ 2
- 1
src/index.php View File

@@ -2,6 +2,7 @@
2 2
 use Tqdev\PhpCrudApi\Api;
3 3
 use Tqdev\PhpCrudApi\Config;
4 4
 use Tqdev\PhpCrudApi\RequestFactory;
5
+use Tqdev\PhpCrudApi\ResponseUtils;
5 6
 
6 7
 // do not reformat the following line
7 8
 spl_autoload_register(function ($class) {include str_replace('\\', '/', __DIR__ . "/$class.php");});
@@ -15,4 +16,4 @@ $config = new Config([
15 16
 $request = RequestFactory::fromGlobals();
16 17
 $api = new Api($config);
17 18
 $response = $api->handle($request);
18
-$response->output();
19
+ResponseUtils::output($response);

+ 2
- 1
test.php View File

@@ -3,6 +3,7 @@ use Tqdev\PhpCrudApi\Api;
3 3
 use Tqdev\PhpCrudApi\Config;
4 4
 use Tqdev\PhpCrudApi\Database\GenericDB;
5 5
 use Tqdev\PhpCrudApi\RequestFactory;
6
+use Tqdev\PhpCrudApi\ResponseUtils;
6 7
 
7 8
 spl_autoload_register(function ($class) {
8 9
     include str_replace('\\', '/', "src\\$class.php");
@@ -63,7 +64,7 @@ function runTest(Config $config, String $file, String $category): int
63 64
         $exp = $parts[$i + 1];
64 65
         $api = new Api($config);
65 66
         $_SERVER['REMOTE_ADDR'] = 'TEST_IP';
66
-        $out = $api->handle(RequestFactory::fromString($in));
67
+        $out = ResponseUtils::toString($api->handle(RequestFactory::fromString($in)));
67 68
         if ($recording) {
68 69
             $parts[$i + 1] = $out;
69 70
         } else if ($out != $exp) {

+ 1
- 1
tests/config/base.php View File

@@ -40,7 +40,7 @@ $settings = [
40 40
     },
41 41
     'customization.afterHandler' => function ($operation, $tableName, $response, $environment) {
42 42
         if ($tableName == 'kunsthåndværk' && $operation == 'increment') {
43
-            $response->addHeader('X-Time-Taken', 0.006/*microtime(true)*/ - $environment->start);
43
+            return $response->withHeader('X-Time-Taken', 0.006/*microtime(true)*/ - $environment->start);
44 44
         }
45 45
     },
46 46
     'debug' => false,

+ 1
- 1
tests/functional/001_records/041_cors_pre_flight.log View File

@@ -6,6 +6,6 @@ Access-Control-Request-Headers: X-XSRF-TOKEN, X-Requested-With
6 6
 200
7 7
 Access-Control-Allow-Headers: Content-Type, X-XSRF-TOKEN, X-Authorization
8 8
 Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH
9
-Access-Control-Allow-Credentials: true
10 9
 Access-Control-Max-Age: 1728000
10
+Access-Control-Allow-Credentials: true
11 11
 Access-Control-Allow-Origin: http://example.com

Loading…
Cancel
Save