Skip to content

Commit 8edc070

Browse files
committed
pipe-middleware
1 parent db409b1 commit 8edc070

23 files changed

+326
-465
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ $app->emit($app->handle((new ServerRequestFactory())->createFromGlobals()));
122122
* [CallbackMiddleware][70]
123123
* [ExceptionMiddleware][71]
124124
* [LazyMiddleware][72]
125-
* [MiddlewareDispatcher][73]
125+
* [PipeMiddleware][73]
126126
* [RouteMatcherMiddleware][74]
127127
* [SlimCallbackMiddleware][75]
128128
* [SlimLazyMiddleware][76]
@@ -156,6 +156,7 @@ $app->emit($app->handle((new ServerRequestFactory())->createFromGlobals()));
156156

157157
## Migration
158158

159+
* [5.x to 6.x][214]
159160
* [4.x to 5.x][213]
160161
* [3.x to 4.x][212]
161162
* [2.x to 3.x][211]
@@ -205,7 +206,7 @@ $app->emit($app->handle((new ServerRequestFactory())->createFromGlobals()));
205206
[70]: doc/Middleware/CallbackMiddleware.md
206207
[71]: doc/Middleware/ExceptionMiddleware.md
207208
[72]: doc/Middleware/LazyMiddleware.md
208-
[73]: doc/Middleware/MiddlewareDispatcher.md
209+
[73]: doc/Middleware/PipeMiddleware.md
209210
[74]: doc/Middleware/RouteMatcherMiddleware.md
210211
[75]: doc/Middleware/SlimCallbackMiddleware.md
211212
[76]: doc/Middleware/SlimLazyMiddleware.md
@@ -233,5 +234,6 @@ $app->emit($app->handle((new ServerRequestFactory())->createFromGlobals()));
233234
[211]: doc/Migration/2.x-3.x.md
234235
[212]: doc/Migration/3.x-4.x.md
235236
[213]: doc/Migration/4.x-5.x.md
237+
[214]: doc/Migration/5.x-6.x.md
236238

237239
[219]: doc/Migration/Slim-Chubbyphp.md

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"extra": {
6565
"branch-alias": {
66-
"dev-master": "5.2-dev"
66+
"dev-master": "6.0-dev"
6767
}
6868
},
6969
"scripts": {

doc/Middleware/MiddlewareDispatcher.md renamed to doc/Middleware/PipeMiddleware.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# MiddlewareDispatcher
1+
# PipeMiddleware
22

33
## Methods
44

@@ -7,7 +7,7 @@
77
```php
88
<?php
99

10-
use Chubbyphp\Framework\Middleware\MiddlewareDispatcher;
10+
use Chubbyphp\Framework\Middleware\PipeMiddleware;
1111
use Psr\Http\Message\ResponseInterface;
1212
use Psr\Http\Message\ServerRequestInterface;
1313
use Psr\Http\Server\MiddlewareInterface;
@@ -37,7 +37,7 @@ $handler = new class() implements RequestHandlerInterface {
3737
}
3838
};
3939

40-
$middlewareDispatcher = new MiddlewareDispatcher();
40+
$pipeMiddleware = new PipeMiddleware([$middleware1, $middleware2]);
4141

42-
$response = $middlewareDispatcher->dispatch([$middleware1, $middleware2], $handler, $request);
42+
$response = $pipeMiddleware->dispatch($request, $handler);
4343
```

doc/Migration/5.x-6.x.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 5.x to 6.x
2+
3+
`Chubbyphp\Framework\Middleware\MiddlewareDispatcher` gets dropped and replaced by `Chubbyphp\Framework\Middleware\PipeMiddleware`.
4+
`Chubbyphp\Framework\Middleware\MiddlewareDispatcher` as an implements of `Chubbyphp\Framework\Middleware\MiddlewareDispatcherInterface` which is gone as well.
5+
6+
This makes the framework as bit less flexible for special use cases, but easier in use for the majority.
7+
8+
Resulting changes:
9+
- `Chubbyphp\Framework\Handler\RouteRequestHandler::__construct` does not take a `Chubbyphp\Framework\Middleware\MiddlewareDispatcherInterface` as argument anymore.
10+
- `Chubbyphp\Framework\Application::__construct` does not take a `Chubbyphp\Framework\Middleware\MiddlewareDispatcherInterface` and `Chubbyphp\Framework\Handler\RouteRequestHandler` as argument anymore.
11+
12+
**If you need a custom `Chubbyphp\Framework\Middleware\PipeMiddleware` for your use case:**
13+
14+
I suggest you:
15+
- Create an own `Chubbyphp\Framework\Application` and `Chubbyphp\Framework\Handler\RouteRequestHandler` onces you read the code you'll see it's little to replace and to maintain yourself.
16+
- Create an issue convincing me to find a better solution with you in collaboration
17+
18+
`Chubbyphp\Framework\Collection` gets dropped, cause i do not believe the additional runtime security for typing arrays was worth the performance hit. Use phpstan or something compatible to prevent mistakes in usage.

doc/RequestHandler/RouteRequestHandler.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
```php
88
<?php
99

10-
use Chubbyphp\Framework\Middleware\MiddlewareDispatcher;
1110
use Chubbyphp\Framework\RequestHandler\RouteRequestHandler;
1211
use Psr\Http\Message\ServerRequestInterface;
1312
use Some\Psr7\Response;
@@ -16,9 +15,7 @@ use Some\Psr7\ServerRequest;
1615
$request = new ServerRequest();
1716
$response = new Response();
1817

19-
$middlewareDispatcher = new MiddlewareDispatcher();
18+
$handler = new RouteRequestHandler();
2019

21-
$callbackHandler = new RouteRequestHandler($middlewareDispatcher);
22-
23-
$response = $callbackHandler->handle($request);
20+
$response = $handler->handle($request);
2421
```

phpstan.neon

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
parameters:
2-
ignoreErrors:
3-
-
4-
message: '/Instanceof between Chubbyphp\\Framework\\Router\\RouteInterface and Chubbyphp\\Framework\\Router\\RouteInterface will always evaluate to true./'
5-
path: %currentWorkingDirectory%/src/Router/RoutesByName.php
2+
ignoreErrors: []

src/Application.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
use Chubbyphp\Framework\Emitter\Emitter;
88
use Chubbyphp\Framework\Emitter\EmitterInterface;
9-
use Chubbyphp\Framework\Middleware\MiddlewareDispatcher;
10-
use Chubbyphp\Framework\Middleware\MiddlewareDispatcherInterface;
9+
use Chubbyphp\Framework\Middleware\PipeMiddleware;
1110
use Chubbyphp\Framework\RequestHandler\RouteRequestHandler;
1211
use Psr\Http\Message\ResponseInterface;
1312
use Psr\Http\Message\ServerRequestInterface;
@@ -16,14 +15,9 @@
1615

1716
final class Application implements RequestHandlerInterface
1817
{
19-
/**
20-
* @var array<MiddlewareInterface>
21-
*/
22-
private array $middlewares;
23-
24-
private MiddlewareDispatcherInterface $middlewareDispatcher;
18+
private PipeMiddleware $pipeMiddleware;
2519

26-
private RequestHandlerInterface $requestHandler;
20+
private RequestHandlerInterface $routeRequestHandler;
2721

2822
private EmitterInterface $emitter;
2923

@@ -32,13 +26,10 @@ final class Application implements RequestHandlerInterface
3226
*/
3327
public function __construct(
3428
array $middlewares,
35-
?MiddlewareDispatcherInterface $middlewareDispatcher = null,
36-
?RequestHandlerInterface $requestHandler = null,
3729
?EmitterInterface $emitter = null
3830
) {
39-
$this->middlewares = (new Collection($middlewares, [MiddlewareInterface::class]))->toArray();
40-
$this->middlewareDispatcher = $middlewareDispatcher ?? new MiddlewareDispatcher();
41-
$this->requestHandler = $requestHandler ?? new RouteRequestHandler($this->middlewareDispatcher);
31+
$this->pipeMiddleware = new PipeMiddleware($middlewares);
32+
$this->routeRequestHandler = new RouteRequestHandler();
4233
$this->emitter = $emitter ?? new Emitter();
4334
}
4435

@@ -49,11 +40,7 @@ public function __invoke(ServerRequestInterface $request): ResponseInterface
4940

5041
public function handle(ServerRequestInterface $request): ResponseInterface
5142
{
52-
return $this->middlewareDispatcher->dispatch(
53-
$this->middlewares,
54-
$this->requestHandler,
55-
$request
56-
);
43+
return $this->pipeMiddleware->process($request, $this->routeRequestHandler);
5744
}
5845

5946
public function emit(ResponseInterface $response): void

src/Collection.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Middleware/MiddlewareDispatcher.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Middleware/MiddlewareDispatcherInterface.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)