Download the PHP package ellipse/router-fastroute without Composer
On this page you can find all versions of the php package ellipse/router-fastroute. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ellipse/router-fastroute
More information about ellipse/router-fastroute
Files in ellipse/router-fastroute
Package router-fastroute
Short Description FastRoute Psr-15 middleware and request handler
License MIT
Homepage https://github.com/ellipsephp/router-fastroute
Informations about the package router-fastroute
FastRoute
FastRoute Psr-15 middleware and request handler.
Require php >= 7.0
Installation composer require ellipse/router-fastroute
Run tests ./vendor/bin/kahlan
- Usage as request handler
- Usage as middleware
- Group count based middleware and request handler
- Dispatcher factories helpers
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 => 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 ofFastRoute\Dispatcher
. - An
Ellipse\Router\Exceptions\MatchedHandlerTypeException
is thrown when the route handler matched by the fastroute dispatcher is not an implementation ofPsr\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.
Usage as middleware
This package provides an Ellipse\Router\FastRouteMiddleware
Psr-15 middleware also taking a fastroute dispatcher factory as parameter.
Under the hood it creates a FastRouteRequestHandler
with the given factory and use it to handle the request. When a NotFoundException
is thrown, the request processing is delegated to the next middleware.
Group count based middleware and request handler
As fastroute dispatchers are usually group count based, this package provides an Ellipse\Router\FastRoute\GroupCountBasedMiddleware
and an Ellipse\Router\FastRoute\GroupCountBasedRequestHandler
taking only a route definition callback as parameter allowing to easily create group count based fastroute middleware and request handler.
Dispatcher factories helpers
This package provides two dispatcher factories helpers proxying the fastroute ones: Ellipse\Router\FastRoute\SimpleDispatcher
and Ellipse\Router\FastRoute\CachedDispatcher
.
Those two classes are just callables proxying their respective fastroute functions to produce a dispatcher when the FastRouteRequestHandler
handles the request.
All versions of router-fastroute with dependencies
psr/http-message Version ^1.0
ellipse/router-adapter Version ^1.0
nikic/fast-route Version ^1.2
ellipse/type-errors Version ^1.0