PHP Class Autarky\Routing\Route

Show file Open project: autarky/framework Class Usage Examples

Protected Properties

Property Type Description
$controller callable
$methods array
$name null | string
$options array
$params array | null
$pattern string
$router Router

Public Methods

Method Description
__construct ( array $methods, string $pattern, callable $controller, string $name = null, array $options = [] )
__set_state ( array $data ) : static Re-build a Route object from data that has been var_export-ed.
addAfterHook ( string $hook ) Add an after hook.
addBeforeHook ( string $hook ) Add a before hook.
addHook ( string $when, string $hook ) Add a before or after hook.
getAfterHooks ( ) : string[] Get the route's after hooks.
getBeforeHooks ( ) : string[] Get the route's before hooks.
getController ( ) : callable Get the callable controller for the route.
getMethods ( ) : string[] Get the methods the route responds to.
getName ( ) : string | null Get the route's name.
getOption ( $option ) : mixed Get a route option.
getOptions ( ) : array Get the route options.
getParams ( ) : array Get the parameters. Can only be called on a route that has been matched against an URI (i.e. setParams has been called)
getPattern ( ) : string Get the URI pattern the route should match against.
setParams ( array $params ) When a match against the route has been confirmed, extract the parameters from the URI and pass them as an associative array to this method.
setRouter ( Autarky\Routing\RouterInterface $router ) Set the router the route objects use.

Method Details

__construct() public method

public __construct ( array $methods, string $pattern, callable $controller, string $name = null, array $options = [] )
$methods array HTTP methods allowed for this route
$pattern string
$controller callable
$name string
$options array

__set_state() public static method

Re-build a Route object from data that has been var_export-ed.
public static __set_state ( array $data ) : static
$data array
return static

addAfterHook() public method

Add an after hook.
public addAfterHook ( string $hook )
$hook string

addBeforeHook() public method

Add a before hook.
public addBeforeHook ( string $hook )
$hook string

addHook() public method

Add a before or after hook.
public addHook ( string $when, string $hook )
$when string "before" or "after"
$hook string

getAfterHooks() public method

Get the route's after hooks.
public getAfterHooks ( ) : string[]
return string[]

getBeforeHooks() public method

Get the route's before hooks.
public getBeforeHooks ( ) : string[]
return string[]

getController() public method

Get the callable controller for the route.
public getController ( ) : callable
return callable

getMethods() public method

Get the methods the route responds to.
public getMethods ( ) : string[]
return string[]

getName() public method

Get the route's name.
public getName ( ) : string | null
return string | null

getOption() public method

Get a route option.
public getOption ( $option ) : mixed
$option string
return mixed Returns null if option not set.

getOptions() public method

Get the route options.
public getOptions ( ) : array
return array

getParams() public method

Get the parameters. Can only be called on a route that has been matched against an URI (i.e. setParams has been called)
public getParams ( ) : array
return array

getPattern() public method

Get the URI pattern the route should match against.
public getPattern ( ) : string
return string

setParams() public method

When a match against the route has been confirmed, extract the parameters from the URI and pass them as an associative array to this method.
public setParams ( array $params )
$params array

setRouter() public static method

Somewhat of a hack to make var_export caching work.
public static setRouter ( Autarky\Routing\RouterInterface $router )
$router Autarky\Routing\RouterInterface

Property Details

$controller protected property

protected callable $controller
return callable

$methods protected property

protected array $methods
return array

$name protected property

protected null|string $name
return null | string

$options protected property

protected array $options
return array

$params protected property

protected array|null $params
return array | null

$pattern protected property

protected string $pattern
return string

$router protected static property

protected static Router,Autarky\Routing $router
return Router