Skip to content

Commit e26df66

Browse files
authored
Update README.md
1 parent 0d87530 commit e26df66

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# middleware-collection-request-handler
22

3-
Lightweight & simple PSR-15 server request handler implementation to handle middleware collection.
3+
Lightweight & dead simple PSR-15 Server Request Handler implementation to process a collection of middlewares.
44

55
![PHP from Packagist](https://img.shields.io/packagist/php-v/noglitchyo/middleware-collection-request-handler.svg)
66
[![Build Status](https://travis-ci.org/noglitchyo/middleware-collection-request-handler.svg?branch=master)](https://travis-ci.org/noglitchyo/middleware-collection-request-handler)
@@ -10,17 +10,21 @@ Lightweight & simple PSR-15 server request handler implementation to handle midd
1010

1111
### Description
1212

13-
Request handler implementing the [RequestHandlerInterface](https://github.com/php-fig/http-server-handler/blob/master/src/RequestHandlerInterface.php)
14-
and able to manage a collection of middlewares implementing the [MiddlewareInterface](https://github.com/php-fig/http-server-middleware/blob/master/src/MiddlewareInterface.php).
13+
PSR-7 Request Handler implementing the [RequestHandlerInterface](https://github.com/php-fig/http-server-handler/blob/master/src/RequestHandlerInterface.php)
14+
and able to manage a collection of Middlewares implementing the [MiddlewareInterface](https://github.com/php-fig/http-server-middleware/blob/master/src/MiddlewareInterface.php).
1515

16-
This request handler attempts to provide interoperability to process a collection of middlewares and
17-
give the possibility to define the strategy on how middlewares will be processed.
16+
It comes with a set of middleware collections using different strategy on how to provide the middlewares to the RequestHandler, and also provide a dead simple collection interface to implement in a glimpse your own strategy.
17+
18+
### Goals
19+
20+
- Simplicity
21+
- Interoperability
1822

1923
### Getting started
2024

2125
#### Requirements
2226

23-
- PHP 7.3
27+
- PHP >= 7.3
2428

2529
#### Installation
2630

@@ -38,8 +42,8 @@ Some examples of "default request handler":
3842
- with the [ADR pattern](https://en.wikipedia.org/wiki/Action%E2%80%93domain%E2%80%93responder), the default request handler might be your action class.
3943
- with the [MVC pattern](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller), the default request handler might be the action method of your controller.
4044

41-
It is possible to directly provide a `callable` using the factory method `RequestHandler::fromCallable()`.
42-
It will generate a generic instance of RequestHandlerInterface wrapping the `callable` inside.
45+
It is possible to directly provide a `callable` and use the factory method `RequestHandler::fromCallable(callable $callable)`.
46+
It will create an anonymous instance of RequestHandlerInterface wrapping the given `callable` inside.
4347

4448
- `$middlewareCollection` ([MiddlewareCollectionInterface](https://github.com/noglitchyo/middleware-collection-request-handler/blob/master/src/MiddlewareCollectionInterface.php))
4549

@@ -48,11 +52,10 @@ Some standard implementations are provided with different strategies: [stack (LI
4852

4953
##### Example
5054

51-
Below, this is how simple it is to get your middleware stack running:
55+
Below, this is how simple it is to get the middleware handler running:
5256

5357
```php
5458
<?php
55-
5659
use NoGlitchYo\MiddlewareCollectionRequestHandler\RequestHandler;
5760
use NoGlitchYo\MiddlewareCollectionRequestHandler\Collection\SplStackMiddlewareCollection;
5861
use Psr\Http\Server\MiddlewareInterface;
@@ -69,6 +72,11 @@ $middlewareCollection = new SplStackMiddlewareCollection([
6972
}
7073
]);
7174

75+
// Let's add one more middleware in the collection (this time, from a callable)
76+
$middlewareCollection->addFromCallable(function(ServerRequestInterface $request, RequestHandlerInterface $handler){
77+
return $handler->handle($request);
78+
});
79+
7280
// Instantiate a new request handler with a default handler and the middleware collection.
7381
$requestHandler = RequestHandler::fromCallable(
7482
function (ServerRequestInterface $serverRequest){
@@ -84,7 +92,7 @@ $response = $requestHandler->handle(/* ServerRequestInterface */);
8492

8593
#### Create a custom MiddlewareCollectionInterface implementation
8694

87-
It is easy to create you own MiddlewareCollectionInterface implementation if you need. The interface requires only 3 methods:
95+
It is easy to create a new MiddlewareCollectionInterface implementation if needed. The interface requires only 3 methods:
8896
```php
8997
<?php
9098
interface MiddlewareCollectionInterface

0 commit comments

Comments
 (0)