Skip to content

Commit

Permalink
move fallback response to handlers package
Browse files Browse the repository at this point in the history
  • Loading branch information
pmall committed Mar 12, 2018
1 parent b0d8675 commit 7b8e567
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 108 deletions.
29 changes: 0 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ This package provides a [Psr-15](https://www.php-fig.org/psr/psr-15/) dispatcher
**Run tests** `./vendor/bin/kahlan`

- [Getting started](https://github.com/ellipsephp/dispatcher#getting-started)
- [Using a fallback response](https://github.com/ellipsephp/dispatcher#using-a-fallback-response)
- [Middleware and request handler resolving](https://github.com/ellipsephp/dispatcher#middleware-and-request-handler-resolving)
- [Composing a dispatcher](https://github.com/ellipsephp/dispatcher#composing-a-dispatcher)

Expand Down Expand Up @@ -88,34 +87,6 @@ $dispatcher = $dispatcher->with(new SomeMiddleware1);
$response = $dispatcher->handle($request);
```

## Using a fallback response

A common practice is to define a fallback response to return when no middleware can produce a response on its own. It can be achieved by using a request handler taking this default response as parameter and returning it when its `->handle()` method is called. In order to spare the developper the creation of such a basic request handler, this package provides an `Ellipse\Dispatcher\FallbackResponse` class implementing this logic.

```php
<?php

namespace App;

use Ellipse\Dispatcher;
use Ellipse\Dispatcher\FallbackResponse;

// Get some incoming Psr-7 request.
$request = some_psr7_request_factory();

// Get some fallback Psr-7 response, here with a 404 status code.
$response = some_psr7_response_factory()->withStatus(404);

// Create a dispatcher using two middleware and a fallback response as request handler.
$dispatcher = new Dispatcher(new FallbackResponse($response), [
new SomeMiddleware1,
new SomeMiddleware2,
]);

// Here the fallback response is returned when no middleware return a response on its own.
$response = $dispatcher->handle($request);
```

## Middleware and request handler resolving

Another common practice is to allow callables and class names registered in a container to be used as regular middleware/request handler.
Expand Down
41 changes: 0 additions & 41 deletions spec/Dispatcher/FallbackResponse.spec.php

This file was deleted.

38 changes: 0 additions & 38 deletions src/Dispatcher/FallbackResponse.php

This file was deleted.

0 comments on commit 7b8e567

Please sign in to comment.