Skip to content

Commit d8c85b9

Browse files
authoredApr 25, 2018
Merge pull request #3 from idealo/use-new-psr15-interfaces
use new psr-15 interface packages
2 parents 7589180 + afb97c1 commit d8c85b9

File tree

8 files changed

+92
-1496
lines changed

8 files changed

+92
-1496
lines changed
 

‎.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: php
22
php:
33
- '7.0'
4+
- '7.1'
5+
- '7.2'
46

57
before_script: composer install
68
script: phpunit

‎Readme.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# PHP Middleware Stack
2-
[![Build Status](https://travis-ci.com/idealo/php-middleware-stack.svg?token=dB3owzyXmEKz9x3RX1AW&branch=master)](https://travis-ci.com/idealo/php-middleware-stack)
2+
[![Build Status](https://travis-ci.org/idealo/php-middleware-stack.svg?branch=master)](https://travis-ci.org/idealo/php-middleware-stack)
33

4-
This is an implementation of [PSR-15 Draft](https://github.com/php-fig/fig-standards/blob/master/proposed/http-middleware/middleware.md) using the proposed Interface package [http-interop/http-middleware](https://github.com/http-interop/http-middleware) for PHP7+ runtime environment.
4+
This is an implementation of [PSR-15](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-15-request-handlers.md) using the proposed Interface packages [psr/http-server-middleware](https://github.com/php-fig/http-server-middleware) and [psr/http-server-handler](https://github.com/php-fig/http-server-handler) for PHP7+ runtime environment.
55

66
It enables a sequential execution of middlewares that use a PSR-7 conform Response/Request implementation.
77

@@ -27,22 +27,22 @@ $stack = new Stack(
2727
$middleware3
2828
);
2929

30-
$stackResponse = $stack->process($request);
30+
$stackResponse = $stack->handle($request);
3131

3232

3333
```
3434

3535
## Usage
3636
**idealo/php-middleware-stack** provides the ```Idealo\Middleware\Stack``` class. All it has to know in order to be instantiable is:
3737
* an instance of ```Psr\Http\Message\ResponseInterface``` as the default response
38-
* and middlewares, that implement the ```Psr\Http\Middleware\ServerMiddlewareInterface```
38+
* and middlewares, that implement the ```Psr\Http\Server\MiddlewareInterface```
3939

40-
To perform a sequential processing of injected middlewares you have to call stack's ```process``` method with:
41-
* an instance of ```Psr\Http\Message\RequestInterface```.
40+
To perform a sequential processing of injected middlewares you have to call stack's ```handle``` method with:
41+
* an instance of ```Psr\Http\Message\ServerRequestInterface```.
4242

43-
By default stack's ```process``` method returns the injected response object. If any middleware decides to answer on it's own, than the response object of this certain middleware is returned.
43+
By default stack's ```handle``` method returns the injected response object. If any middleware decides to answer on it's own, than the response object of this certain middleware is returned.
4444

45-
Stack implements ```Interop\Http\ServerMiddleware\DelegateInterface```.
45+
Stack implements ```Psr\Http\Server\RequestHandlerInterface```.
4646

4747
## For example
4848

@@ -53,12 +53,12 @@ Stack implements ```Interop\Http\ServerMiddleware\DelegateInterface```.
5353
// you decide what middleware you want to put in a stack.
5454
use Psr\Http\Message\ResponseInterface;
5555
use Psr\Http\Message\ServerRequestInterface;
56-
use Interop\Http\ServerMiddleware\DelegateInterface;
57-
use Interop\Http\ServerMiddleware\MiddlewareInterface;
56+
use Psr\Http\Server\RequestHandlerInterface;
57+
use Psr\Http\Server\MiddlewareInterface;
5858

5959
class TrickyMiddleware implements MiddlewareInterface
6060
{
61-
public function process(ServerRequestInterface $request, DelegateInterface $frame) : ResponseInterface
61+
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
6262
{
6363
$requestBody = $request->getBody();
6464
try {
@@ -67,7 +67,7 @@ class TrickyMiddleware implements MiddlewareInterface
6767
return new CustomExceptionResponse($exception);
6868
}
6969

70-
return $frame->process($request);
70+
return $handler->handle($request);
7171
}
7272
}
7373

@@ -95,7 +95,7 @@ $stack = new \Idealo\Middleware\Stack(
9595
new LessTrickyMiddleware()
9696
);
9797

98-
$stackResponse = $stack->process($request);
98+
$stackResponse = $stack->handle($request);
9999

100100
// if everything goes well then
101101
var_dump($stackResponse === $defaultResponse); // gives: true

‎composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@
2525
"require": {
2626
"php": "^7.0",
2727
"psr/http-message": "^1.0",
28-
"http-interop/http-middleware": "^0.4"
28+
"psr/http-server-middleware": "^1.0",
29+
"psr/http-server-handler": "^1.0"
2930
},
3031
"require-dev": {
31-
"phpunit/phpunit": "^5.6"
32+
"phpunit/phpunit": "^6.5"
3233
},
3334
"autoload": {
3435
"psr-4": {
3536
"Idealo\\Middleware\\": "src/"
3637
}
38+
},
39+
"autoload-dev": {
40+
"psr-4": {
41+
"Idealo\\Middleware\\Tests\\": "tests/"
42+
}
3743
}
3844
}

0 commit comments

Comments
 (0)