Skip to content

Commit c915a27

Browse files
authored
Merge pull request #28 from chubbyphp/pipe-middleware
pipe-middleware
2 parents 412d911 + c0de4d6 commit c915a27

23 files changed

Lines changed: 326 additions & 493 deletions

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Any Router which implements `Chubbyphp\Framework\Router\RouteMatcherInterface` c
6969
Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-framework][60].
7070

7171
```bash
72-
composer require chubbyphp/chubbyphp-framework "^5.3" \
72+
composer require chubbyphp/chubbyphp-framework "^6.0" \
7373
chubbyphp/chubbyphp-framework-router-fastroute "^2.3" \
7474
slim/psr7 "^1.7"
7575
```
@@ -124,7 +124,7 @@ $app->emit($app->handle((new ServerRequestFactory())->createFromGlobals()));
124124
* [CallbackMiddleware][70]
125125
* [ExceptionMiddleware][71]
126126
* [LazyMiddleware][72]
127-
* [MiddlewareDispatcher][73]
127+
* [PipeMiddleware][73]
128128
* [RouteMatcherMiddleware][74]
129129
* [SlimCallbackMiddleware][75]
130130
* [SlimLazyMiddleware][76]
@@ -158,6 +158,7 @@ $app->emit($app->handle((new ServerRequestFactory())->createFromGlobals()));
158158

159159
## Migration
160160

161+
* [5.x to 6.x][214]
161162
* [4.x to 5.x][213]
162163
* [3.x to 4.x][212]
163164
* [2.x to 3.x][211]
@@ -208,7 +209,7 @@ $app->emit($app->handle((new ServerRequestFactory())->createFromGlobals()));
208209
[70]: doc/Middleware/CallbackMiddleware.md
209210
[71]: doc/Middleware/ExceptionMiddleware.md
210211
[72]: doc/Middleware/LazyMiddleware.md
211-
[73]: doc/Middleware/MiddlewareDispatcher.md
212+
[73]: doc/Middleware/PipeMiddleware.md
212213
[74]: doc/Middleware/RouteMatcherMiddleware.md
213214
[75]: doc/Middleware/SlimCallbackMiddleware.md
214215
[76]: doc/Middleware/SlimLazyMiddleware.md
@@ -236,5 +237,6 @@ $app->emit($app->handle((new ServerRequestFactory())->createFromGlobals()));
236237
[211]: doc/Migration/2.x-3.x.md
237238
[212]: doc/Migration/3.x-4.x.md
238239
[213]: doc/Migration/4.x-5.x.md
240+
[214]: doc/Migration/5.x-6.x.md
239241

240242
[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.3-dev"
66+
"dev-master": "6.0-dev"
6767
}
6868
},
6969
"scripts": {
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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` as argument anymore.
11+
12+
`Chubbyphp\Framework\Collection` is gone, use phpstan if you want to make sure you providing the correct types on array of.

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 & 24 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,30 +15,17 @@
1615

1716
final class Application implements RequestHandlerInterface
1817
{
19-
/**
20-
* @var array<MiddlewareInterface>
21-
*/
22-
private array $middlewares;
23-
24-
private MiddlewareDispatcherInterface $middlewareDispatcher;
25-
26-
private RequestHandlerInterface $requestHandler;
27-
28-
private EmitterInterface $emitter;
18+
private PipeMiddleware $pipeMiddleware;
2919

3020
/**
3121
* @param array<MiddlewareInterface> $middlewares
3222
*/
3323
public function __construct(
3424
array $middlewares,
35-
?MiddlewareDispatcherInterface $middlewareDispatcher = null,
36-
?RequestHandlerInterface $requestHandler = null,
37-
?EmitterInterface $emitter = null
25+
private RequestHandlerInterface $routeRequestHandler = new RouteRequestHandler(),
26+
private EmitterInterface $emitter = new Emitter()
3827
) {
39-
$this->middlewares = (new Collection($middlewares, [MiddlewareInterface::class]))->toArray();
40-
$this->middlewareDispatcher = $middlewareDispatcher ?? new MiddlewareDispatcher();
41-
$this->requestHandler = $requestHandler ?? new RouteRequestHandler($this->middlewareDispatcher);
42-
$this->emitter = $emitter ?? new Emitter();
28+
$this->pipeMiddleware = new PipeMiddleware($middlewares);
4329
}
4430

4531
public function __invoke(ServerRequestInterface $request): ResponseInterface
@@ -49,11 +35,7 @@ public function __invoke(ServerRequestInterface $request): ResponseInterface
4935

5036
public function handle(ServerRequestInterface $request): ResponseInterface
5137
{
52-
return $this->middlewareDispatcher->dispatch(
53-
$this->middlewares,
54-
$this->requestHandler,
55-
$request
56-
);
38+
return $this->pipeMiddleware->process($request, $this->routeRequestHandler);
5739
}
5840

5941
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)