PHP Class Bramus\Router\Router

Show file Open project: bramus/router

Protected Properties

Property Type Description
$notFoundCallback The function to be executed when no route has been matched

Public Methods

Method Description
all ( string $pattern, object | callable $fn ) Shorthand for a route accessed using any method
before ( string $methods, string $pattern, object | callable $fn ) Store a before middleware route and a handling function to be executed when accessed using one of the specified methods
delete ( string $pattern, object | callable $fn ) Shorthand for a route accessed using DELETE
get ( string $pattern, object | callable $fn ) Shorthand for a route accessed using GET
getRequestHeaders ( ) : array Get all request headers
getRequestMethod ( ) : string Get the request method used, taking overrides into account
match ( string $methods, string $pattern, object | callable $fn ) Store a route and a handling function to be executed when accessed using one of the specified methods
mount ( string $baseRoute, callable $fn ) Mounts a collection of callbacks onto a base route
options ( string $pattern, object | callable $fn ) Shorthand for a route accessed using OPTIONS
patch ( string $pattern, object | callable $fn ) Shorthand for a route accessed using PATCH
post ( string $pattern, object | callable $fn ) Shorthand for a route accessed using POST
put ( string $pattern, object | callable $fn ) Shorthand for a route accessed using PUT
run ( object | callable $callback = null ) : boolean Execute the router: Loop all defined before middleware's and routes, and execute the handling function if a match was found
set404 ( object | callable $fn ) Set the 404 handling function

Protected Methods

Method Description
getBasePath ( ) : string Return server base Path, and define it if isn't defined.
getCurrentUri ( ) : string Define the current relative URI

Private Methods

Method Description
handle ( array $routes, boolean $quitAfterRun = false ) : integer Handle a a set of routes: if a match is found, execute the relating handling function

Method Details

all() public method

Shorthand for a route accessed using any method
public all ( string $pattern, object | callable $fn )
$pattern string A route pattern such as /about/system
$fn object | callable The handling function to be executed

before() public method

Store a before middleware route and a handling function to be executed when accessed using one of the specified methods
public before ( string $methods, string $pattern, object | callable $fn )
$methods string Allowed methods, | delimited
$pattern string A route pattern such as /about/system
$fn object | callable The handling function to be executed

delete() public method

Shorthand for a route accessed using DELETE
public delete ( string $pattern, object | callable $fn )
$pattern string A route pattern such as /about/system
$fn object | callable The handling function to be executed

get() public method

Shorthand for a route accessed using GET
public get ( string $pattern, object | callable $fn )
$pattern string A route pattern such as /about/system
$fn object | callable The handling function to be executed

getBasePath() protected method

Return server base Path, and define it if isn't defined.
protected getBasePath ( ) : string
return string

getCurrentUri() protected method

Define the current relative URI
protected getCurrentUri ( ) : string
return string

getRequestHeaders() public method

Get all request headers
public getRequestHeaders ( ) : array
return array The request headers

getRequestMethod() public method

Get the request method used, taking overrides into account
public getRequestMethod ( ) : string
return string The Request method to handle

match() public method

Store a route and a handling function to be executed when accessed using one of the specified methods
public match ( string $methods, string $pattern, object | callable $fn )
$methods string Allowed methods, | delimited
$pattern string A route pattern such as /about/system
$fn object | callable The handling function to be executed

mount() public method

Mounts a collection of callbacks onto a base route
public mount ( string $baseRoute, callable $fn )
$baseRoute string The route sub pattern to mount the callbacks on
$fn callable The callback method

options() public method

Shorthand for a route accessed using OPTIONS
public options ( string $pattern, object | callable $fn )
$pattern string A route pattern such as /about/system
$fn object | callable The handling function to be executed

patch() public method

Shorthand for a route accessed using PATCH
public patch ( string $pattern, object | callable $fn )
$pattern string A route pattern such as /about/system
$fn object | callable The handling function to be executed

post() public method

Shorthand for a route accessed using POST
public post ( string $pattern, object | callable $fn )
$pattern string A route pattern such as /about/system
$fn object | callable The handling function to be executed

put() public method

Shorthand for a route accessed using PUT
public put ( string $pattern, object | callable $fn )
$pattern string A route pattern such as /about/system
$fn object | callable The handling function to be executed

run() public method

Execute the router: Loop all defined before middleware's and routes, and execute the handling function if a match was found
public run ( object | callable $callback = null ) : boolean
$callback object | callable Function to be executed after a matching route was handled (= after router middleware)
return boolean

set404() public method

Set the 404 handling function
public set404 ( object | callable $fn )
$fn object | callable The function to be executed

Property Details

$notFoundCallback protected property

The function to be executed when no route has been matched
protected $notFoundCallback