Download the PHP package webiik/router without Composer
On this page you can find all versions of the php package webiik/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webiik/router
More information about webiik/router
Files in webiik/router
Package router
Short Description The Router is passive, multi-lingual regex router. It supports route names, route parameters, route controllers and route middleware.
License MIT
Homepage https://www.webiik.com
Informations about the package router
Router
The Router is passive, multi-lingual regex router. It supports route names, route parameters, route controllers and route middleware. Passive means that it doesn't set HTTP headers and it doesn't invoke route controllers and middleware. It just tests a request URI against the defined routes and returns all necessary data to build a route.
Installation
Example
Configuration
setBaseURI
setBaseURI() sets the base directory of your index.php file relatively to web-server root.
Every time your index.php file isn't in the web-server root directory, you have to set dir in which is located.
setDefaultLang
setDefaultLang() sets the default language of routes without defined $lang parameter. $defaultLang must be two characters long. The default value is en.
setDefaultLangInURI
setDefaultLangInURI() determines if default language is part of URI e.g. /en/. The default value is FALSE.
Adding
addRoute
addRoute() adds NewRoute to the Router and returns NewRoute.
Parameters:
- methods array of route http methods
- route route URI regex (without delimiters)
- controller string representation of controller e.g. controllerName:methodName
- name route name
- lang two letter route lang prefix, if it's not set, the default lang is used instead
Check
match
match() checks if current request URI matches some of defined route and returns Route.
getHttpCode
getHttpCode() returns http code of the result of last match().
Getting
getBaseURL
getBaseURL() returns base URL of your app e.g. https://www.webiik.com
getURI
getURI() returns route's URI. If it can't find the route or some of the required route parameters is missing, then it returns the empty string. After calling getURI(), you can get missing parameters by calling getMissingParameters()
getURL
getURL() same as getURI(), but returns full URL.
getMissingParameters
getMissingParameters() returns missing parameters after calling getURI() or getURL().
getRegexParameters
getRegexParameters() returns array with route regex parameters e.g. ['0' => '(?\<name>[a-z])?', '1' => '([a-z])']. If the route doesn't exist, it returns false.
Route
The Route is the result of match(). It contains handy information about the current route.
getController
getController() returns array with route controller and controller method to run.
getName
getName() returns route name.
getLang
getLang() returns route language.
getMw
getMw() returns array with route middleware.
getParameters
getParameters() returns parameters injected during Route construction e.g. ['name' => 'dolly', '1' => 'dolly', '2' => 'hello'].