Download the PHP package phower/router without Composer
On this page you can find all versions of the php package phower/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phower/router
More information about phower/router
Files in phower/router
Package router
Short Description PHP routing package compliant with PSR-7.
License MIT
Informations about the package router
Phower Router
PHP routing package compliant with PSR-7.
Requirements
Phower Router requires:
Instalation
Add Phower Router to any PHP project using Composer:
Usage
Routing is the process to match and drive an HTTP request to a previously given route. This process requires a Router instance with one or more Routes to evaluate against the request.
Routes
Each Route must have a name and a definition. Optionally it may also have constraints, default values for optional segments and allowed methods.
A simple Route example to match requests to the root path ():
Another example for a Route matching requests to path, with a required argument and an optional argument:
Note that arguments are preceeded with a colon () and to make them optional we must use squared brackets.
To force an argument to some pattern we can specify a third argument in form of an associative array containing a regular expression for each constraint.
In previous example we may wish to constrain argument to only accept digits:
We can also provide default values for optional arguments. In case they are not specified in the the original request then the default value will take their place. It is also possible to attach other values to a Route using the defaults array:
Some routes are also expected to match against a request with a specific method. For example to just match requests we can tell that using a fifth argument in the Route signature
A static factory method is available to create routes from a configuration array:
Assembling a Route instance means to build its URL from the required arguments:
Router
Router is a stack of routes with methods to match a given HTTP request and to assemble URLs for a named route.
Creating a Router instance just requires an array containing weither Route instances or configuration arrays to instantiate routes:
Matching an HTTP request requires an instance of RequestInterface as argument:
We can also assemble a route by name from a Router instance containing that named route:
Running Tests
Tests are available in a separated namespace and can run with PHPUnit in the command line:
Coding Standards
Phower code is written under PSR-2 coding style standard. To enforce that CodeSniffer tools are also provided and can run as:
Reporting Issues
In case you find issues with this code please open a ticket in Github Issues at https://github.com/phower/router/issues.
Contributors
Open Source is made of contribuition. If you want to contribute to Phower please follow these steps:
- Fork latest version into your own repository.
- Write your changes or additions and commit them.
- Follow PSR-2 coding style standard.
- Make sure you have unit tests with full coverage to your changes.
- Go to Github Pull Requests at https://github.com/phower/router/pulls and create a new request.
Thank you!
Changes and Versioning
All relevant changes on this code are logged in a separated log file.
Version numbers follow recommendations from Semantic Versioning.
License
Phower code is maintained under The MIT License.