PHP Class Webiny\Component\Router\Route\Route

Inheritance: use trait Webiny\Component\StdLib\StdLibTrait
Show file Open project: Webiny/Framework Class Usage Examples

Public Methods

Method Description
__construct ( string $path, string | array $callback, array $options = [], string $host = '', array $schemes = [], array $methods = [] ) Base constructor.
addOption ( string $name, array $attributes ) Adds a single route option.
compile ( ) : CompiledRoute Compiles the route object and returns an instance of CompiledRoute.
getCallback ( ) : string | array Get the attached callback name.
getHost ( ) : string Get current host name.
getMethods ( ) : array Get the current defined methods.
getOptions ( ) : array Returns route options.
getPath ( ) : string Get the route path.
getRealPath ( ) : string Get the real path.
getSchemes ( ) : array Get the current defined schemes.
getTags ( ) : array Get the route tags.
hasOption ( string $name ) : boolean Checks if route has options attached to the given parameter.
setCallback ( string | array $callback ) Set the route callback.
setHost ( string $host ) Sets the host name to the route.
setMethods ( array | string $methods ) Match only requests that are within this set of methods.
setOptions ( array $options ) Set route options.
setPath ( string $path ) Sets the route path.
setSchemes ( array | string $schemes ) Match only requests that are within this set of schemes.
setTags ( array $tags ) Sets the route tags.

Method Details

__construct() public method

Base constructor.
public __construct ( string $path, string | array $callback, array $options = [], string $host = '', array $schemes = [], array $methods = [] )
$path string Path with parameter names that identifies the route.
$callback string | array Attached callback for this route.
$options array List of options, mostly for parameters. Common option keys are 'pattern' and 'default'. Pattern defines the regular expression for the defined parameter. Default sets the default value for the parameter if it's not matched withing the route.
$host string Fully qualified host name that will be added as a filer for matching the url.
$schemes array An array of supported schemas that the url must match.
$methods array An array of supported methods that the url must match.

addOption() public method

Adds a single route option.
public addOption ( string $name, array $attributes )
$name string Name of the parameter to which the option should be attached.
$attributes array An array of options.

compile() public method

Compiles the route object and returns an instance of CompiledRoute.
public compile ( ) : CompiledRoute
return CompiledRoute

getCallback() public method

Get the attached callback name.
public getCallback ( ) : string | array
return string | array

getHost() public method

Example host name: webiny.com | www.webiny.com
public getHost ( ) : string
return string

getMethods() public method

Get the current defined methods.
public getMethods ( ) : array
return array

getOptions() public method

Returns route options.
public getOptions ( ) : array
return array

getPath() public method

Get the route path.
public getPath ( ) : string
return string

getRealPath() public method

Get the real path.
public getRealPath ( ) : string
return string

getSchemes() public method

Get the current defined schemes.
public getSchemes ( ) : array
return array

getTags() public method

Get the route tags.
public getTags ( ) : array
return array

hasOption() public method

Checks if route has options attached to the given parameter.
public hasOption ( string $name ) : boolean
$name string Name of the route parameter.
return boolean

setCallback() public method

Set the route callback.
public setCallback ( string | array $callback )
$callback string | array Callback that will be attached to this route. Note that this callback can be overwritten during the routing process.

setHost() public method

When defining a host name, the route must first match the host in order that it could match the route path.
public setHost ( string $host )
$host string Host name.

setMethods() public method

Example methods: POST | GET
public setMethods ( array | string $methods )
$methods array | string Method(s) to match.

setOptions() public method

Set route options.
public setOptions ( array $options )
$options array An array of options. Each option must have a name and a list of attributes and their values. Common attributes are 'prefix' and 'default'.

setPath() public method

Sets the route path.
public setPath ( string $path )
$path string Route path.

setSchemes() public method

Example scheme: http | https
public setSchemes ( array | string $schemes )
$schemes array | string Scheme(s) to match.

setTags() public method

Sets the route tags.
public setTags ( array $tags )
$tags array