Skip to content

Commit

Permalink
new version
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Oct 22, 2018
1 parent c82a003 commit 33dd801
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Fixed

- Use `phpstan` as a dev dependency to detect bugs
## [1.2.0] - 2018-10-22

### Added

- Added `responseFactory` option to `__construct`

### Deprecated

- `responseFactory()` option as a method. Use the contructor argument instead.

### Fixed

- Use `phpstan` as a dev dependency to detect bugs

## [1.1.0] - 2018-08-04

### Added
Expand Down
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,35 @@ $response = $dispatcher->dispatch(new ServerRequest('/hello/world'));

**FastRoute** allows anything to be defined as the router handler (a closure, callback, action object, controller class, etc). The middleware will store this handler in a request attribute.

## Options
## API

### `__construct(FastRoute\Dispatcher $dispatcher)`
### `__construct`

The dispatcher instance to use.
Type | Required | Description
--------------|----------|------------
`FastRoute\Dispatcher` | Yes | The dispatcher instance to use.
`Psr\Http\Message\ResponseFactoryInterface` | No | A PSR-17 factory to create the error responses (`404` or `405`). If it's not defined, use [Middleware\Utils\Factory](https://github.com/middlewares/utils#factory) to detect it automatically.

### `attribute(string $attribute)`

The attribute name used to store the handler in the server request. The default attribute name is `request-handler`.
### `attribute`

#### `responseFactory(Psr\Http\Message\ResponseFactoryInterface $responseFactory)`
Changes the attribute name used to store the handler in the server request. The default name is `request-handler`.

A PSR-17 factory to create the error responses (`404` or `405`).
Type | Required | Description
--------------|----------|------------
`string` | Yes | The new attribute name

```php
$dispatcher = new Dispatcher([
//Save the route handler in an attribute called "route"
(new Middlewares\FastRoute($dispatcher))->attribute('route'),

//Execute the route handler
(new Middlewares\RequestHandler())->attribute('route')
]);

$response = $dispatcher->dispatch(new ServerRequest('/hello/world'));
```
---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.
Expand Down
4 changes: 2 additions & 2 deletions src/FastRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace Middlewares;

use FastRoute\Dispatcher;
use Middlewares\Utils\Traits\HasResponseFactory;
use Middlewares\Utils\Factory;
use Middlewares\Utils\Traits\HasResponseFactory;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -27,7 +27,7 @@ class FastRoute implements MiddlewareInterface
private $attribute = 'request-handler';

/**
* Set the Dispatcher instance.
* Set the Dispatcher instance and optionally the response factory to return the error responses.
*/
public function __construct(Dispatcher $router, ResponseFactoryInterface $responseFactory = null)
{
Expand Down

0 comments on commit 33dd801

Please sign in to comment.