Download the PHP package quimcalpe/router without Composer
On this page you can find all versions of the php package quimcalpe/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download quimcalpe/router
More information about quimcalpe/router
Files in quimcalpe/router
Package router
Short Description Regexp based Router, easy to use and with a rich feature set
License MIT
Homepage https://github.com/quimcalpe/router
Informations about the package router
quimcalpe/router
Regexp based Router, easy to use and with a rich feature set. It includes various built-in dispatchers, and we also provide an interface to develop fully customized dispatchers for your project.
Install
Via Composer
Requirements
The following versions of PHP are supported by this version.
- PHP 8.1
Basic Usage
Constructor optional Route[] parameter
You can alternatively pass an array of Route
objects to Router's constructor, and routes will be created;
This array can be included from another file, enabling config separation in a simple way.
Route Providers
If you want to import a bunch of Routes from a specific package/namespace/bundle and you want to keep routes organized, you can use Route providers, define your provider like this:
And then initialize the Router with:
Route Patterns
Basic regexp patterns are supported, some are already included:
[^/]+
as default- 'word' =>
\w+
- 'number' =>
\d+
- 'slug' =>
[A-Za-z0-9_-]+
Patterns can be used this way:
You can define your own patterns:
Wildcards
Wildcards in routes can be used with WildcardDispatcher
:
Request Response
Standard Request - Response workflow with Symfony HttpFoundation components is supported with RequestResponseDispatcher
:
PSR-7 HTTP Message
A built-in PSR7Dispatcher
is available to work with PHP-FIG's PSR-7 HTTP Message standard implementations, an example using Zend Diactoros and a simple PSR-7 Response Sender would look like this:
Custom Dispatcher
You can create your custom Dispatcher, implementing DispatcherInterface
:
QuimCalpe\Router\Route\ParsedRoute
is a small Value Object with controller()
and params()
methods already parsed by Router::parse
.
Trailing slash
Default behaviour is to honour distinction between routes with and wothout trailing slashes:
You can disable this behaviour with disableTrailingSlashCheck
method:
Testing
License
The MIT License (MIT). Please see License File for more information.