Maurits van der Schee vor 5 Jahren
Ursprung
Commit
bd1af34bdf

+ 53
- 54
api.php Datei anzeigen

@@ -247,6 +247,22 @@ interface UriInterface
247 247
     public function __toString();
248 248
 }
249 249
 
250
+// file: src/Psr/Http/Server/MiddlewareInterface.php
251
+
252
+interface MiddlewareInterface
253
+{
254
+    
255
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface;
256
+}
257
+
258
+// file: src/Psr/Http/Server/RequestHandlerInterface.php
259
+
260
+interface RequestHandlerInterface
261
+{
262
+    
263
+    public function handle(ServerRequestInterface $request): ResponseInterface;
264
+}
265
+
250 266
 // file: src/Nyholm/Psr7/Factory/Psr17Factory.php
251 267
 
252 268
 final class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
@@ -4419,16 +4435,9 @@ class TypeConverter
4419 4435
     }
4420 4436
 }
4421 4437
 
4422
-// file: src/Tqdev/PhpCrudApi/Middleware/Base/Handler.php
4423
-
4424
-interface Handler
4425
-{
4426
-    public function handle(ServerRequestInterface $request): ResponseInterface;
4427
-}
4428
-
4429 4438
 // file: src/Tqdev/PhpCrudApi/Middleware/Base/Middleware.php
4430 4439
 
4431
-abstract class Middleware implements Handler
4440
+abstract class Middleware implements MiddlewareInterface
4432 4441
 {
4433 4442
     protected $next;
4434 4443
     protected $responder;
@@ -4441,11 +4450,6 @@ abstract class Middleware implements Handler
4441 4450
         $this->properties = $properties;
4442 4451
     }
4443 4452
 
4444
-    public function setNext(Handler $handler) /*: void*/
4445
-    {
4446
-        $this->next = $handler;
4447
-    }
4448
-
4449 4453
     protected function getArrayProperty(string $key, string $default): array
4450 4454
     {
4451 4455
         return array_filter(array_map('trim', explode(',', $this->getProperty($key, $default))));
@@ -4479,7 +4483,7 @@ class VariableStore
4479 4483
 
4480 4484
 // file: src/Tqdev/PhpCrudApi/Middleware/Router/Router.php
4481 4485
 
4482
-interface Router extends Handler
4486
+interface Router extends RequestHandlerInterface
4483 4487
 {
4484 4488
     public function register(string $method, string $path, array $handler);
4485 4489
 
@@ -4538,13 +4542,7 @@ class SimpleRouter implements Router
4538 4542
 
4539 4543
     public function load(Middleware $middleware) /*: void*/
4540 4544
     {
4541
-        if (count($this->middlewares) > 0) {
4542
-            $next = $this->middlewares[0];
4543
-        } else {
4544
-            $next = $this;
4545
-        }
4546
-        $middleware->setNext($next);
4547
-        array_unshift($this->middlewares, $middleware);
4545
+        array_push($this->middlewares, $middleware);
4548 4546
     }
4549 4547
 
4550 4548
     public function route(ServerRequestInterface $request): ResponseInterface
@@ -4553,11 +4551,7 @@ class SimpleRouter implements Router
4553 4551
             $data = gzcompress(json_encode($this->routes, JSON_UNESCAPED_UNICODE));
4554 4552
             $this->cache->set('PathTree', $data, $this->ttl);
4555 4553
         }
4556
-        $obj = $this;
4557
-        if (count($this->middlewares) > 0) {
4558
-            $obj = $this->middlewares[0];
4559
-        }
4560
-        return $obj->handle($request);
4554
+        return $this->handle($request);
4561 4555
     }
4562 4556
 
4563 4557
     private function getRouteNumbers(ServerRequestInterface $request): array
@@ -4570,6 +4564,11 @@ class SimpleRouter implements Router
4570 4564
 
4571 4565
     public function handle(ServerRequestInterface $request): ResponseInterface
4572 4566
     {
4567
+        if (count($this->middlewares)) {
4568
+            $handler = array_pop($this->middlewares);
4569
+            return $handler->process($request, $this);
4570
+        }
4571
+
4573 4572
         $routeNumbers = $this->getRouteNumbers($request);
4574 4573
         if (count($routeNumbers) == 0) {
4575 4574
             return $this->responder->error(ErrorCode::ROUTE_NOT_FOUND, $request->getRequestTarget());
@@ -4599,7 +4598,7 @@ class SimpleRouter implements Router
4599 4598
 
4600 4599
 class AjaxOnlyMiddleware extends Middleware
4601 4600
 {
4602
-    public function handle(ServerRequestInterface $request): ResponseInterface
4601
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
4603 4602
     {
4604 4603
         $method = $request->getMethod();
4605 4604
         $excludeMethods = $this->getArrayProperty('excludeMethods', 'OPTIONS,GET');
@@ -4610,7 +4609,7 @@ class AjaxOnlyMiddleware extends Middleware
4610 4609
                 return $this->responder->error(ErrorCode::ONLY_AJAX_REQUESTS_ALLOWED, $method);
4611 4610
             }
4612 4611
         }
4613
-        return $this->next->handle($request);
4612
+        return $next->handle($request);
4614 4613
     }
4615 4614
 }
4616 4615
 
@@ -4673,7 +4672,7 @@ class AuthorizationMiddleware extends Middleware
4673 4672
         }
4674 4673
     }
4675 4674
 
4676
-    public function handle(ServerRequestInterface $request): ResponseInterface
4675
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
4677 4676
     {
4678 4677
         $path = RequestUtils::getPathSegment($request, 1);
4679 4678
         $operation = RequestUtils::getOperation($request);
@@ -4688,7 +4687,7 @@ class AuthorizationMiddleware extends Middleware
4688 4687
             VariableStore::set('authorization.tableHandler', $this->getProperty('tableHandler', ''));
4689 4688
             VariableStore::set('authorization.columnHandler', $this->getProperty('columnHandler', ''));
4690 4689
         }
4691
-        return $this->next->handle($request);
4690
+        return $next->handle($request);
4692 4691
     }
4693 4692
 }
4694 4693
 
@@ -4761,7 +4760,7 @@ class BasicAuthMiddleware extends Middleware
4761 4760
         return base64_decode(strtr($parts[1], '-_', '+/'));
4762 4761
     }
4763 4762
 
4764
-    public function handle(ServerRequestInterface $request): ResponseInterface
4763
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
4765 4764
     {
4766 4765
         if (session_status() == PHP_SESSION_NONE) {
4767 4766
             session_start();
@@ -4791,7 +4790,7 @@ class BasicAuthMiddleware extends Middleware
4791 4790
                 return $response;
4792 4791
             }
4793 4792
         }
4794
-        return $this->next->handle($request);
4793
+        return $next->handle($request);
4795 4794
     }
4796 4795
 }
4797 4796
 
@@ -4813,7 +4812,7 @@ class CorsMiddleware extends Middleware
4813 4812
         return $found;
4814 4813
     }
4815 4814
 
4816
-    public function handle(ServerRequestInterface $request): ResponseInterface
4815
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
4817 4816
     {
4818 4817
         $method = $request->getMethod();
4819 4818
         $origin = count($request->getHeader('Origin')) ? $request->getHeader('Origin')[0] : '';
@@ -4843,7 +4842,7 @@ class CorsMiddleware extends Middleware
4843 4842
                 $response = $response->withHeader('Access-Control-Expose-Headers', $exposeHeaders);
4844 4843
             }
4845 4844
         } else {
4846
-            $response = $this->next->handle($request);
4845
+            $response = $next->handle($request);
4847 4846
         }
4848 4847
         if ($origin) {
4849 4848
             $allowCredentials = $this->getProperty('allowCredentials', 'true');
@@ -4868,7 +4867,7 @@ class CustomizationMiddleware extends Middleware
4868 4867
         $this->reflection = $reflection;
4869 4868
     }
4870 4869
 
4871
-    public function handle(ServerRequestInterface $request): ResponseInterface
4870
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
4872 4871
     {
4873 4872
         $operation = RequestUtils::getOperation($request);
4874 4873
         $tableName = RequestUtils::getPathSegment($request, 2);
@@ -4878,7 +4877,7 @@ class CustomizationMiddleware extends Middleware
4878 4877
             $result = call_user_func($beforeHandler, $operation, $tableName, $request, $environment);
4879 4878
             $request = $result ?: $request;
4880 4879
         }
4881
-        $response = $this->next->handle($request);
4880
+        $response = $next->handle($request);
4882 4881
         $afterHandler = $this->getProperty('afterHandler', '');
4883 4882
         if ($afterHandler !== '') {
4884 4883
             $result = call_user_func($afterHandler, $operation, $tableName, $response, $environment);
@@ -4917,7 +4916,7 @@ class FirewallMiddleware extends Middleware
4917 4916
         return false;
4918 4917
     }
4919 4918
 
4920
-    public function handle(ServerRequestInterface $request): ResponseInterface
4919
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
4921 4920
     {
4922 4921
         $reverseProxy = $this->getProperty('reverseProxy', '');
4923 4922
         if ($reverseProxy) {
@@ -4931,7 +4930,7 @@ class FirewallMiddleware extends Middleware
4931 4930
         if (!$this->isIpAllowed($ipAddress, $allowedIpAddresses)) {
4932 4931
             $response = $this->responder->error(ErrorCode::TEMPORARY_OR_PERMANENTLY_BLOCKED, '');
4933 4932
         } else {
4934
-            $response = $this->next->handle($request);
4933
+            $response = $next->handle($request);
4935 4934
         }
4936 4935
         return $response;
4937 4936
     }
@@ -4967,7 +4966,7 @@ class IpAddressMiddleware extends Middleware
4967 4966
         return (object) $context;
4968 4967
     }
4969 4968
 
4970
-    public function handle(ServerRequestInterface $request): ResponseInterface
4969
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
4971 4970
     {
4972 4971
         $operation = RequestUtils::getOperation($request);
4973 4972
         if (in_array($operation, ['create', 'update', 'increment'])) {
@@ -4990,7 +4989,7 @@ class IpAddressMiddleware extends Middleware
4990 4989
                 }
4991 4990
             }
4992 4991
         }
4993
-        return $this->next->handle($request);
4992
+        return $next->handle($request);
4994 4993
     }
4995 4994
 }
4996 4995
 
@@ -5006,7 +5005,7 @@ class JoinLimitsMiddleware extends Middleware
5006 5005
         $this->reflection = $reflection;
5007 5006
     }
5008 5007
 
5009
-    public function handle(ServerRequestInterface $request): ResponseInterface
5008
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
5010 5009
     {
5011 5010
         $operation = RequestUtils::getOperation($request);
5012 5011
         $params = RequestUtils::getParams($request);
@@ -5035,7 +5034,7 @@ class JoinLimitsMiddleware extends Middleware
5035 5034
             $request = RequestUtils::setParams($request, $params);
5036 5035
             VariableStore::set("joinLimits.maxRecords", $maxRecords);
5037 5036
         }
5038
-        return $this->next->handle($request);
5037
+        return $next->handle($request);
5039 5038
     }
5040 5039
 }
5041 5040
 
@@ -5154,7 +5153,7 @@ class JwtAuthMiddleware extends Middleware
5154 5153
         return $parts[1];
5155 5154
     }
5156 5155
 
5157
-    public function handle(ServerRequestInterface $request): ResponseInterface
5156
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
5158 5157
     {
5159 5158
         if (session_status() == PHP_SESSION_NONE) {
5160 5159
             session_start();
@@ -5176,7 +5175,7 @@ class JwtAuthMiddleware extends Middleware
5176 5175
                 return $this->responder->error(ErrorCode::AUTHENTICATION_REQUIRED, '');
5177 5176
             }
5178 5177
         }
5179
-        return $this->next->handle($request);
5178
+        return $next->handle($request);
5180 5179
     }
5181 5180
 }
5182 5181
 
@@ -5237,7 +5236,7 @@ class MultiTenancyMiddleware extends Middleware
5237 5236
         return $request->withParsedBody($multi ? $records : $records[0]);
5238 5237
     }
5239 5238
 
5240
-    public function handle(ServerRequestInterface $request): ResponseInterface
5239
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
5241 5240
     {
5242 5241
         $handler = $this->getProperty('handler', '');
5243 5242
         if ($handler !== '') {
@@ -5260,7 +5259,7 @@ class MultiTenancyMiddleware extends Middleware
5260 5259
                 }
5261 5260
             }
5262 5261
         }
5263
-        return $this->next->handle($request);
5262
+        return $next->handle($request);
5264 5263
     }
5265 5264
 }
5266 5265
 
@@ -5276,7 +5275,7 @@ class PageLimitsMiddleware extends Middleware
5276 5275
         $this->reflection = $reflection;
5277 5276
     }
5278 5277
 
5279
-    public function handle(ServerRequestInterface $request): ResponseInterface
5278
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
5280 5279
     {
5281 5280
         $operation = RequestUtils::getOperation($request);
5282 5281
         if ($operation == 'list') {
@@ -5300,7 +5299,7 @@ class PageLimitsMiddleware extends Middleware
5300 5299
             }
5301 5300
             $request = RequestUtils::setParams($request, $params);
5302 5301
         }
5303
-        return $this->next->handle($request);
5302
+        return $next->handle($request);
5304 5303
     }
5305 5304
 }
5306 5305
 
@@ -5329,7 +5328,7 @@ class SanitationMiddleware extends Middleware
5329 5328
         return (object) $context;
5330 5329
     }
5331 5330
 
5332
-    public function handle(ServerRequestInterface $request): ResponseInterface
5331
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
5333 5332
     {
5334 5333
         $operation = RequestUtils::getOperation($request);
5335 5334
         if (in_array($operation, ['create', 'update', 'increment'])) {
@@ -5352,7 +5351,7 @@ class SanitationMiddleware extends Middleware
5352 5351
                 }
5353 5352
             }
5354 5353
         }
5355
-        return $this->next->handle($request);
5354
+        return $next->handle($request);
5356 5355
     }
5357 5356
 }
5358 5357
 
@@ -5388,7 +5387,7 @@ class ValidationMiddleware extends Middleware
5388 5387
         return null;
5389 5388
     }
5390 5389
 
5391
-    public function handle(ServerRequestInterface $request): ResponseInterface
5390
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
5392 5391
     {
5393 5392
         $operation = RequestUtils::getOperation($request);
5394 5393
         if (in_array($operation, ['create', 'update', 'increment'])) {
@@ -5416,7 +5415,7 @@ class ValidationMiddleware extends Middleware
5416 5415
                 }
5417 5416
             }
5418 5417
         }
5419
-        return $this->next->handle($request);
5418
+        return $next->handle($request);
5420 5419
     }
5421 5420
 }
5422 5421
 
@@ -5439,7 +5438,7 @@ class XsrfMiddleware extends Middleware
5439 5438
         return $token;
5440 5439
     }
5441 5440
 
5442
-    public function handle(ServerRequestInterface $request): ResponseInterface
5441
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
5443 5442
     {
5444 5443
         $token = $this->getToken();
5445 5444
         $method = $request->getMethod();
@@ -5450,7 +5449,7 @@ class XsrfMiddleware extends Middleware
5450 5449
                 return $this->responder->error(ErrorCode::BAD_OR_MISSING_XSRF_TOKEN, '');
5451 5450
             }
5452 5451
         }
5453
-        return $this->next->handle($request);
5452
+        return $next->handle($request);
5454 5453
     }
5455 5454
 }
5456 5455
 

+ 2
- 5
src/Nyholm/Psr7/ServerRequest.php Datei anzeigen

@@ -1,13 +1,10 @@
1 1
 <?php
2 2
 
3
-declare (strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Nyholm\Psr7;
6 6
 
7
-use Psr\Http\Message\ServerRequestInterface;
8
-use Psr\Http\Message\StreamInterface;
9
-use Psr\Http\Message\UploadedFileInterface;
10
-use Psr\Http\Message\UriInterface;
7
+use Psr\Http\Message\{ServerRequestInterface, StreamInterface, UploadedFileInterface, UriInterface};
11 8
 
12 9
 /**
13 10
  * @author Michael Dowling and contributors to guzzlehttp/psr7

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/AjaxOnlyMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
7 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 9
 use Tqdev\PhpCrudApi\Record\ErrorCode;
@@ -10,7 +11,7 @@ use Tqdev\PhpCrudApi\RequestUtils;
10 11
 
11 12
 class AjaxOnlyMiddleware extends Middleware
12 13
 {
13
-    public function handle(ServerRequestInterface $request): ResponseInterface
14
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
14 15
     {
15 16
         $method = $request->getMethod();
16 17
         $excludeMethods = $this->getArrayProperty('excludeMethods', 'OPTIONS,GET');
@@ -21,6 +22,6 @@ class AjaxOnlyMiddleware extends Middleware
21 22
                 return $this->responder->error(ErrorCode::ONLY_AJAX_REQUESTS_ALLOWED, $method);
22 23
             }
23 24
         }
24
-        return $this->next->handle($request);
25
+        return $next->handle($request);
25 26
     }
26 27
 }

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/AuthorizationMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Column\ReflectionService;
7 8
 use Tqdev\PhpCrudApi\Controller\Responder;
8 9
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
@@ -68,7 +69,7 @@ class AuthorizationMiddleware extends Middleware
68 69
         }
69 70
     }
70 71
 
71
-    public function handle(ServerRequestInterface $request): ResponseInterface
72
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
72 73
     {
73 74
         $path = RequestUtils::getPathSegment($request, 1);
74 75
         $operation = RequestUtils::getOperation($request);
@@ -83,6 +84,6 @@ class AuthorizationMiddleware extends Middleware
83 84
             VariableStore::set('authorization.tableHandler', $this->getProperty('tableHandler', ''));
84 85
             VariableStore::set('authorization.columnHandler', $this->getProperty('columnHandler', ''));
85 86
         }
86
-        return $this->next->handle($request);
87
+        return $next->handle($request);
87 88
     }
88 89
 }

+ 0
- 10
src/Tqdev/PhpCrudApi/Middleware/Base/Handler.php Datei anzeigen

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

+ 2
- 6
src/Tqdev/PhpCrudApi/Middleware/Base/Middleware.php Datei anzeigen

@@ -1,10 +1,11 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Middleware\Base;
3 3
 
4
+use Psr\Http\Server\MiddlewareInterface;
4 5
 use Tqdev\PhpCrudApi\Controller\Responder;
5 6
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
6 7
 
7
-abstract class Middleware implements Handler
8
+abstract class Middleware implements MiddlewareInterface
8 9
 {
9 10
     protected $next;
10 11
     protected $responder;
@@ -17,11 +18,6 @@ abstract class Middleware implements Handler
17 18
         $this->properties = $properties;
18 19
     }
19 20
 
20
-    public function setNext(Handler $handler) /*: void*/
21
-    {
22
-        $this->next = $handler;
23
-    }
24
-
25 21
     protected function getArrayProperty(string $key, string $default): array
26 22
     {
27 23
         return array_filter(array_map('trim', explode(',', $this->getProperty($key, $default))));

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/BasicAuthMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
7 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 9
 use Tqdev\PhpCrudApi\Record\ErrorCode;
@@ -75,7 +76,7 @@ class BasicAuthMiddleware extends Middleware
75 76
         return base64_decode(strtr($parts[1], '-_', '+/'));
76 77
     }
77 78
 
78
-    public function handle(ServerRequestInterface $request): ResponseInterface
79
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
79 80
     {
80 81
         if (session_status() == PHP_SESSION_NONE) {
81 82
             session_start();
@@ -105,6 +106,6 @@ class BasicAuthMiddleware extends Middleware
105 106
                 return $response;
106 107
             }
107 108
         }
108
-        return $this->next->handle($request);
109
+        return $next->handle($request);
109 110
     }
110 111
 }

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/CorsMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
7 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 9
 use Tqdev\PhpCrudApi\Record\ErrorCode;
@@ -24,7 +25,7 @@ class CorsMiddleware extends Middleware
24 25
         return $found;
25 26
     }
26 27
 
27
-    public function handle(ServerRequestInterface $request): ResponseInterface
28
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
28 29
     {
29 30
         $method = $request->getMethod();
30 31
         $origin = count($request->getHeader('Origin')) ? $request->getHeader('Origin')[0] : '';
@@ -54,7 +55,7 @@ class CorsMiddleware extends Middleware
54 55
                 $response = $response->withHeader('Access-Control-Expose-Headers', $exposeHeaders);
55 56
             }
56 57
         } else {
57
-            $response = $this->next->handle($request);
58
+            $response = $next->handle($request);
58 59
         }
59 60
         if ($origin) {
60 61
             $allowCredentials = $this->getProperty('allowCredentials', 'true');

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/CustomizationMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Column\ReflectionService;
7 8
 use Tqdev\PhpCrudApi\Controller\Responder;
8 9
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
@@ -19,7 +20,7 @@ class CustomizationMiddleware extends Middleware
19 20
         $this->reflection = $reflection;
20 21
     }
21 22
 
22
-    public function handle(ServerRequestInterface $request): ResponseInterface
23
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
23 24
     {
24 25
         $operation = RequestUtils::getOperation($request);
25 26
         $tableName = RequestUtils::getPathSegment($request, 2);
@@ -29,7 +30,7 @@ class CustomizationMiddleware extends Middleware
29 30
             $result = call_user_func($beforeHandler, $operation, $tableName, $request, $environment);
30 31
             $request = $result ?: $request;
31 32
         }
32
-        $response = $this->next->handle($request);
33
+        $response = $next->handle($request);
33 34
         $afterHandler = $this->getProperty('afterHandler', '');
34 35
         if ($afterHandler !== '') {
35 36
             $result = call_user_func($afterHandler, $operation, $tableName, $response, $environment);

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/FirewallMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
7 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 9
 use Tqdev\PhpCrudApi\Record\ErrorCode;
@@ -34,7 +35,7 @@ class FirewallMiddleware extends Middleware
34 35
         return false;
35 36
     }
36 37
 
37
-    public function handle(ServerRequestInterface $request): ResponseInterface
38
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
38 39
     {
39 40
         $reverseProxy = $this->getProperty('reverseProxy', '');
40 41
         if ($reverseProxy) {
@@ -48,7 +49,7 @@ class FirewallMiddleware extends Middleware
48 49
         if (!$this->isIpAllowed($ipAddress, $allowedIpAddresses)) {
49 50
             $response = $this->responder->error(ErrorCode::TEMPORARY_OR_PERMANENTLY_BLOCKED, '');
50 51
         } else {
51
-            $response = $this->next->handle($request);
52
+            $response = $next->handle($request);
52 53
         }
53 54
         return $response;
54 55
     }

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/IpAddressMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Column\ReflectionService;
7 8
 use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
8 9
 use Tqdev\PhpCrudApi\Controller\Responder;
@@ -38,7 +39,7 @@ class IpAddressMiddleware extends Middleware
38 39
         return (object) $context;
39 40
     }
40 41
 
41
-    public function handle(ServerRequestInterface $request): ResponseInterface
42
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
42 43
     {
43 44
         $operation = RequestUtils::getOperation($request);
44 45
         if (in_array($operation, ['create', 'update', 'increment'])) {
@@ -61,6 +62,6 @@ class IpAddressMiddleware extends Middleware
61 62
                 }
62 63
             }
63 64
         }
64
-        return $this->next->handle($request);
65
+        return $next->handle($request);
65 66
     }
66 67
 }

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/JoinLimitsMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Column\ReflectionService;
7 8
 use Tqdev\PhpCrudApi\Controller\Responder;
8 9
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
@@ -20,7 +21,7 @@ class JoinLimitsMiddleware extends Middleware
20 21
         $this->reflection = $reflection;
21 22
     }
22 23
 
23
-    public function handle(ServerRequestInterface $request): ResponseInterface
24
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
24 25
     {
25 26
         $operation = RequestUtils::getOperation($request);
26 27
         $params = RequestUtils::getParams($request);
@@ -49,6 +50,6 @@ class JoinLimitsMiddleware extends Middleware
49 50
             $request = RequestUtils::setParams($request, $params);
50 51
             VariableStore::set("joinLimits.maxRecords", $maxRecords);
51 52
         }
52
-        return $this->next->handle($request);
53
+        return $next->handle($request);
53 54
     }
54 55
 }

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/JwtAuthMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
7 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 9
 use Tqdev\PhpCrudApi\Record\ErrorCode;
@@ -121,7 +122,7 @@ class JwtAuthMiddleware extends Middleware
121 122
         return $parts[1];
122 123
     }
123 124
 
124
-    public function handle(ServerRequestInterface $request): ResponseInterface
125
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
125 126
     {
126 127
         if (session_status() == PHP_SESSION_NONE) {
127 128
             session_start();
@@ -143,6 +144,6 @@ class JwtAuthMiddleware extends Middleware
143 144
                 return $this->responder->error(ErrorCode::AUTHENTICATION_REQUIRED, '');
144 145
             }
145 146
         }
146
-        return $this->next->handle($request);
147
+        return $next->handle($request);
147 148
     }
148 149
 }

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/MultiTenancyMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Column\ReflectionService;
7 8
 use Tqdev\PhpCrudApi\Controller\Responder;
8 9
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
@@ -68,7 +69,7 @@ class MultiTenancyMiddleware extends Middleware
68 69
         return $request->withParsedBody($multi ? $records : $records[0]);
69 70
     }
70 71
 
71
-    public function handle(ServerRequestInterface $request): ResponseInterface
72
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
72 73
     {
73 74
         $handler = $this->getProperty('handler', '');
74 75
         if ($handler !== '') {
@@ -91,6 +92,6 @@ class MultiTenancyMiddleware extends Middleware
91 92
                 }
92 93
             }
93 94
         }
94
-        return $this->next->handle($request);
95
+        return $next->handle($request);
95 96
     }
96 97
 }

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/PageLimitsMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Column\ReflectionService;
7 8
 use Tqdev\PhpCrudApi\Controller\Responder;
8 9
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
@@ -20,7 +21,7 @@ class PageLimitsMiddleware extends Middleware
20 21
         $this->reflection = $reflection;
21 22
     }
22 23
 
23
-    public function handle(ServerRequestInterface $request): ResponseInterface
24
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
24 25
     {
25 26
         $operation = RequestUtils::getOperation($request);
26 27
         if ($operation == 'list') {
@@ -44,6 +45,6 @@ class PageLimitsMiddleware extends Middleware
44 45
             }
45 46
             $request = RequestUtils::setParams($request, $params);
46 47
         }
47
-        return $this->next->handle($request);
48
+        return $next->handle($request);
48 49
     }
49 50
 }

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/Router/Router.php Datei anzeigen

@@ -3,10 +3,10 @@ namespace Tqdev\PhpCrudApi\Middleware\Router;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
-use Tqdev\PhpCrudApi\Middleware\Base\Handler;
6
+use Psr\Http\Server\RequestHandlerInterface;
7 7
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 8
 
9
-interface Router extends Handler
9
+interface Router extends RequestHandlerInterface
10 10
 {
11 11
     public function register(string $method, string $path, array $handler);
12 12
 

+ 7
- 12
src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php Datei anzeigen

@@ -58,13 +58,7 @@ class SimpleRouter implements Router
58 58
 
59 59
     public function load(Middleware $middleware) /*: void*/
60 60
     {
61
-        if (count($this->middlewares) > 0) {
62
-            $next = $this->middlewares[0];
63
-        } else {
64
-            $next = $this;
65
-        }
66
-        $middleware->setNext($next);
67
-        array_unshift($this->middlewares, $middleware);
61
+        array_push($this->middlewares, $middleware);
68 62
     }
69 63
 
70 64
     public function route(ServerRequestInterface $request): ResponseInterface
@@ -73,11 +67,7 @@ class SimpleRouter implements Router
73 67
             $data = gzcompress(json_encode($this->routes, JSON_UNESCAPED_UNICODE));
74 68
             $this->cache->set('PathTree', $data, $this->ttl);
75 69
         }
76
-        $obj = $this;
77
-        if (count($this->middlewares) > 0) {
78
-            $obj = $this->middlewares[0];
79
-        }
80
-        return $obj->handle($request);
70
+        return $this->handle($request);
81 71
     }
82 72
 
83 73
     private function getRouteNumbers(ServerRequestInterface $request): array
@@ -90,6 +80,11 @@ class SimpleRouter implements Router
90 80
 
91 81
     public function handle(ServerRequestInterface $request): ResponseInterface
92 82
     {
83
+        if (count($this->middlewares)) {
84
+            $handler = array_pop($this->middlewares);
85
+            return $handler->process($request, $this);
86
+        }
87
+
93 88
         $routeNumbers = $this->getRouteNumbers($request);
94 89
         if (count($routeNumbers) == 0) {
95 90
             return $this->responder->error(ErrorCode::ROUTE_NOT_FOUND, $request->getRequestTarget());

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/SanitationMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Column\ReflectionService;
7 8
 use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
8 9
 use Tqdev\PhpCrudApi\Controller\Responder;
@@ -33,7 +34,7 @@ class SanitationMiddleware extends Middleware
33 34
         return (object) $context;
34 35
     }
35 36
 
36
-    public function handle(ServerRequestInterface $request): ResponseInterface
37
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
37 38
     {
38 39
         $operation = RequestUtils::getOperation($request);
39 40
         if (in_array($operation, ['create', 'update', 'increment'])) {
@@ -56,6 +57,6 @@ class SanitationMiddleware extends Middleware
56 57
                 }
57 58
             }
58 59
         }
59
-        return $this->next->handle($request);
60
+        return $next->handle($request);
60 61
     }
61 62
 }

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/ValidationMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Column\ReflectionService;
7 8
 use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
8 9
 use Tqdev\PhpCrudApi\Controller\Responder;
@@ -41,7 +42,7 @@ class ValidationMiddleware extends Middleware
41 42
         return null;
42 43
     }
43 44
 
44
-    public function handle(ServerRequestInterface $request): ResponseInterface
45
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
45 46
     {
46 47
         $operation = RequestUtils::getOperation($request);
47 48
         if (in_array($operation, ['create', 'update', 'increment'])) {
@@ -69,6 +70,6 @@ class ValidationMiddleware extends Middleware
69 70
                 }
70 71
             }
71 72
         }
72
-        return $this->next->handle($request);
73
+        return $next->handle($request);
73 74
     }
74 75
 }

+ 3
- 2
src/Tqdev/PhpCrudApi/Middleware/XsrfMiddleware.php Datei anzeigen

@@ -3,6 +3,7 @@ namespace Tqdev\PhpCrudApi\Middleware;
3 3
 
4 4
 use Psr\Http\Message\ResponseInterface;
5 5
 use Psr\Http\Message\ServerRequestInterface;
6
+use Psr\Http\Server\RequestHandlerInterface;
6 7
 use Tqdev\PhpCrudApi\Controller\Responder;
7 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 9
 use Tqdev\PhpCrudApi\Record\ErrorCode;
@@ -24,7 +25,7 @@ class XsrfMiddleware extends Middleware
24 25
         return $token;
25 26
     }
26 27
 
27
-    public function handle(ServerRequestInterface $request): ResponseInterface
28
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
28 29
     {
29 30
         $token = $this->getToken();
30 31
         $method = $request->getMethod();
@@ -35,6 +36,6 @@ class XsrfMiddleware extends Middleware
35 36
                 return $this->responder->error(ErrorCode::BAD_OR_MISSING_XSRF_TOKEN, '');
36 37
             }
37 38
         }
38
-        return $this->next->handle($request);
39
+        return $next->handle($request);
39 40
     }
40 41
 }

+ 10
- 0
src/clone.sh Datei anzeigen

@@ -8,6 +8,16 @@ mkdir -p Psr/Http/Message
8 8
 cp -R http-factory/src/* Psr/Http/Message
9 9
 rm -Rf http-factory
10 10
 
11
+git clone git@github.com:php-fig/http-server-handler
12
+mkdir -p Psr/Http/Server
13
+cp -R http-server-handler/src/* Psr/Http/Server
14
+rm -Rf http-server-handler
15
+
16
+git clone git@github.com:php-fig/http-server-middleware
17
+mkdir -p Psr/Http/Server
18
+cp -R http-server-middleware/src/* Psr/Http/Server
19
+rm -Rf http-server-middleware
20
+
11 21
 git clone git@github.com:Nyholm/psr7.git
12 22
 mkdir -p Nyholm/Psr7
13 23
 cp -R psr7/src/* Nyholm/Psr7

Laden…
Abbrechen
Speichern