PHPackages                             ellipse/router-fastroute - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ellipse/router-fastroute

ActiveLibrary

ellipse/router-fastroute
========================

FastRoute Psr-15 middleware and request handler

1.0.3(8y ago)2172MITPHPPHP &gt;=7.0

Since Jan 30Pushed 8y ago2 watchersCompare

[ Source](https://github.com/ellipsephp/router-fastroute)[ Packagist](https://packagist.org/packages/ellipse/router-fastroute)[ Docs](https://github.com/ellipsephp/router-fastroute)[ RSS](/packages/ellipse-router-fastroute/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (8)Used By (0)

FastRoute
=========

[](#fastroute)

FastRoute [Psr-15](https://www.php-fig.org/psr/psr-15/) middleware and request handler.

**Require** php &gt;= 7.0

**Installation** `composer require ellipse/router-fastroute`

**Run tests** `./vendor/bin/kahlan`

- [Usage as request handler](https://github.com/ellipsephp/router-fastroute#usage-as-request-handler)
- [Usage as middleware](https://github.com/ellipsephp/router-fastroute#usage-as-middleware)
- [Group count based middleware and request handler](https://github.com/ellipsephp/router-fastroute#group-count-based-middleware-and-request-handler)
- [Dispatcher factories helpers](https://github.com/ellipsephp/router-fastroute#dispatcher-factories-helpers)

Usage as request handler
------------------------

[](#usage-as-request-handler)

This package provides an `Ellipse\Router\FastRouteRequestHandler` Psr-15 request handler taking a fastroute dispatcher factory as parameter.

This factory can be any callable returning an implementation of `FastRoute\Dispatcher` and the route handlers it matches are expected to be implementations of `Psr\Http\Server\RequestHandlerInterface`.

When the `FastRouteRequestHandler` handles a request the `Dispatcher` produced by the factory is used to match a Psr-15 request handler. When the matched route pattern contains placeholders, a new request is created with those placeholders =&gt; matched value pairs as request attributes. Finally the matched request handler is proxied with this new request to actually return a response.

Using a factory allows to perform the time consuming task of mapping routes only when the request is handled with the `FastRouteRequestHandler`. If for some reason an application handles the incoming request with another request handler, no time is lost mapping routes for this one.

Regarding exceptions:

- An `Ellipse\Router\Exceptions\FastRouteDispatcherTypeException` is thrown when the factory does not return an implementation of `FastRoute\Dispatcher`.
- An `Ellipse\Router\Exceptions\MatchedHandlerTypeException` is thrown when the route handler matched by the fastroute dispatcher is not an implementation of `Psr\Http\Server\RequestHandlerInterface`.
- An `Ellipse\Router\Exceptions\NotFoundException` is thrown when no route match the url.
- An `Ellipse\Router\Exceptions\MethodNotAllowedException` is thrown when a route matches the url but the request http method is not allowed by the matched route.

```
