Download the PHP package hexbit/router without Composer
On this page you can find all versions of the php package hexbit/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hexbit/router
More information about hexbit/router
Files in hexbit/router
Package router
Short Description Wordpress Router
License MIT
Homepage https://github.com/smarteist/wordpress-router
Informations about the package router
Wordpress Router
A simple PHP router built on SymfonyHttpFoundation and AltoRouter based on laravel API. This library is actually built to make routing easier on the RootsSage starter framework, however it can also be used in other systems
Installation
Usage
Creating Routes
Map Methods
Creating a route is done using the map
function:
In wordpress
If you do not use the WordPress system, use the router class below, and you can attempt to match your current request in appropriate time.
map()
takes 3 parameters:
methods
(array): list of matching request methods, valid values:GET
POST
PUT
PATCH
DELETE
OPTIONS
uri
(string): The URI to match againstaction
(function|string): Either a closure or a Controller string
Route Parameters
Parameters can be defined on routes using the {keyName}
syntax. When a route matches that contains parameters, an instance of the RouteParams
object is passed to the action. Second parameter is an instance of Symfony\Component\HttpFoundation\Request
which contains the information of the current request.
Named Routes
Routes can be named so that their URL can be generated programatically:
If the route requires parameters you can be pass an associative array as a second parameter:
HTTP Verb Shortcuts
Typically you only need to allow one HTTP verb for a route, for these cases the following shortcuts can be used:
Setting the basepath
The router assumes you're working from the route of a domain. If this is not the case you can set the base path:
Controllers
If you'd rather use a class to group related route actions together you can pass a Controller String to map()
instead of a closure. The string takes the format {name of class}@{name of method}
. It is important that you use the complete namespace with the class name.
Example:
Creating Groups
It is common to group similar routes behind a common prefix. This can be achieved using Route Groups:
Matching Routes to Requests
Once you have routes defined, you can attempt to match your current request against them using the match()
function. match()
accepts an instance of Symfony's Request
and returns an instance of Symfony's Symfony\Component\HttpFoundation\Response
:
If you return an instance of Response
from your closure it will be sent back un-touched. If however you return something else, it will be wrapped in an instance of Response
with your return value as the content.
on not found
If no route matches the request, a boolean false
will be returned as match response.
Wordpress Virtual Pages
This feature allows you to create template pages on the fly, and there is no need to have that page in the database.
Now voila! loads virtual page template.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
MIT
All versions of router with dependencies
altorouter/altorouter Version ^2.0
symfony/http-foundation Version ^5.0