Download the PHP package evgsavosin/choco-router without Composer
On this page you can find all versions of the php package evgsavosin/choco-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download evgsavosin/choco-router
More information about evgsavosin/choco-router
Files in evgsavosin/choco-router
Package choco-router
Short Description Modern router for PHP based on regex expression with cache system.
License MIT
Informations about the package choco-router
Choco Router
Modern router for PHP based on regex expression with cache system. Caching has driver support: file system, APCum, Memcached. Defining routes is possible both using methods and attributes from PHP 8.0.
Requirements
- PHP 8.1 or newer;
- APCu (optional);
- Memcached (optional).
Install
Install via composer:
Usage
Basic usage
To use it is necessary to define the call of classes using for example PSR-11 implementation.
Route definition
The route can be defined with method: addRoute(HttpMethod $httpMethod, string $uri, mixed $handler, array $parameters = []): void
. Parameters can be passed {bar}
or {bar?}
with regular expressions ['bar' => '[0-9]+']
.
Real example:
A question mark means the parameter is optional.
The route group is defined using addGroup(string $prefix, callable $callback): void
method. Real example:
HTTP Methods
Full list of methods:
Configuration
You can set the configuration when initializing a simple router:
Attributes
The router supports attributes from PHP 8.0. Example:
Cache
Router has support cache system with defined drivers:
ChocoRouter\Cache\Drivers\FileDriver::class
;ChocoRouter\Cache\Drivers\ApcuDriver::class
;ChocoRouter\Cache\Drivers\MemcachedDriver::class
.
For use cache move definition routes to cache callback:
Contributing
The author has not yet had time to write instructions, but any pull request or issue will be glad.
License
Choco Router has MIT License.