Download the PHP package attogram/router without Composer
On this page you can find all versions of the php package attogram/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download attogram/router
More information about attogram/router
Files in attogram/router
Package router
Short Description Attogram Router for PHP 7 - small, flexible, and surprisingly powerful
License MIT
Homepage https://github.com/attogram/router
Informations about the package router
Attogram Router
Welcome to the Attogram Router for PHP 7 - small, flexible, and surprisingly powerful.
Composer: composer require attogram/router
Git: git clone https://github.com/attogram/router.git
Download: https://github.com/attogram/router/archive/master.zip
License: MIT
Examples
- live demo: https://getitdaily.com/attogram-router/
- demo source: https://github.com/attogram/router/tree/master/examples
Usage
Setup URL rewriting. For example with Apache .htaccess
:
Create your index.php
. For example:
Public Functions
allow
public function allow(string $route, $control)
- Allow and set a control for a route
- $route = a string with the URI list, forward-slash delimited
- Exact routing:
- Home: '/'
- Page: '/foo/bar'
- preceding and trailing slashes are optional, except for top level '/'
- Variable routing:
- use a question mark to denote a URI segment as a variable
- variables are retrieved via
$router->getVar(int $index)
- Examples:
- '/id/?' - retrieve with
getVar(0)
- '/book/?/chapter/?' - retrieve with
getVar(0)
andgetVar(1)
- '/foo/?/?/?' - retrieve with
getVar(0)
,getVar(1)
andgetVar(2)
- '/id/?' - retrieve with
- $control = anything you want
- a string, a closure, an array, an object, an int, a float, whatever!
match
public function match()
- Get the control for the current request, or null if no matching request
getVar
public function getVar(int $index = 0)
- Get a URI segment variable, by index. Starting at 0.
getHome
public function getHome(): string
- Get URL to the installation home
getHomeFull
public function getHomeFull(): string
- Get URL to the installation home, with protocol and host
getCurrent
public function getCurrent(): string
- Get URL to the current request
getCurrentFull
public function getCurrentFull(): string
- Get URL to the current request, with protocol and host
setForceSlash
public function setForceSlash(bool $forceSlash)
- Sets the optional forcing of a trailing slash on all requests
- by default is false
redirect
redirect(string $url, int $httpResponseCode = 301, bool $exitAfter = true)
- Redirect to a new url and exit
- optionally set a response code (301 = permanent, 302 = moved)
getGet
public function getGet(string $name = '')
- Get a global
_GET
variable, or empty string if not found
getPost
public function getPost(string $name = '')
- Get a global
_POST
variable, or empty string if not found
getServer
public function getServer(string $name = '')
- Get a global
_SERVER
variable, or empty string if not found
getHost
public function getHost(): string
- Get the current hostname
getHostFull
public function getHostFull(): string
- Get the current hostname, with protocol and host
getProtocol
public function getProtocol(): string
- Get the current protocol:
http
orhttps