Download the PHP package ignaszak/router without Composer
On this page you can find all versions of the php package ignaszak/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package router
ignaszak/router
Simple object oriented PHP Router
Installing
The package is available via Composer/Packagist, so just add following lines to your composer.json file:
or:
Configuration
The easiest way is to configure mod_rewrite via .htaccess file in site base directory. Example:
Running Tests
Just run phpunit from the working directory
Usage
Demo
Create routes
Add routes
Add tokens
Define default values
Add controller
Add attachment
Group routes
Add defined patterns
Router provides some defined regular expressions such as:
- @base - use to define default route
- @notfound - not found
- @digit - digits [0-9]
- @alpha - alphabetic characters [A-Za-z_-]
- @alnum - alphanumeric characters [A-Za-z0-9_-]
Add global tokens and patterns
Global tokens and patterns are avilable for all routes
Match routes
Host class
Class provides current request and http method. Argument $baseQuery defines folder via site is avilable e.g.: (without trailing slash).
Get response
Reverse Routing
Url can be generated for any defined route with name by using class.
method will return:
- if class is used:
- if class is not defined:
Load routes from Yaml
Yaml file example
You can define routes, global tokens and patterns. Attachment is not available in yaml file. example.yml:
Yaml class
Cache
It is possible to generate cache of routes defined in yaml file or Route class. Cache stores converted routes to regex, so it is no need to read yaml file and convert routes at every request.
All versions of router with dependencies
phpunit/phpunit Version *
mikey179/vfsstream Version *
symfony/yaml Version *