PHP Class Cake\Routing\Route\Route

Not normally created as a standalone. Use Router::connect() to create Routes for your application.
Show file Open project: cakephp/cakephp Class Usage Examples

Public Properties

Property Type Description
$defaults array Default parameters for a Route
$keys array /:controller/:action/:id has 3 key elements
$options array An array of additional parameters for the Route.
$template string The routes template string.

Protected Properties

Property Type Description
$_compiledRoute string The compiled route regular expression
$_extensions array List of connected extensions for this route.
$_greedy string Is this route a greedy route? Greedy routes have a /* in their template
$_name string The name for a route. Fetch with Route::getName();

Public Methods

Method Description
__construct ( string $template, array | string $defaults = [], array $options = [] ) Constructor for a Route
__set_state ( array $fields ) : Route Set state magic method to support var_export
compile ( ) : array Compiles the route's regular expression.
compiled ( ) : boolean Check if a Route has been compiled into a regular expression.
extensions ( null | string | array $extensions = null ) : array | null Get/Set the supported extensions for this route.
getExtensions ( ) : array Get the supported extensions for this route.
getName ( ) : string Get the standardized plugin.controller:action name for a route.
match ( array $url, array $context = [] ) : string | false Check if a URL array matches this route instance.
parse ( string $url, string $method = '' ) : array | false Checks to see if the given URL can be parsed by this route.
setExtensions ( array $extensions ) Set the supported extensions for this route.
staticPath ( ) : string Get the static path portion for this route.

Protected Methods

Method Description
_matchMethod ( array $url ) : boolean Check whether or not the URL's HTTP method matches.
_parseArgs ( string $args, string $context ) : array Parse passed parameters into a list of passed args.
_parseExtension ( string $url ) : array Removes the extension from $url if it contains a registered extension.
_persistParams ( array $url, array $params ) : array Apply persistent parameters to a URL array. Persistent parameters are a special key used during route creation to force route parameters to persist when omitted from a URL array.
_writeRoute ( ) : void Builds a route regular expression.
_writeUrl ( array $params, array $pass = [], array $query = [] ) : string Converts a matching route array into a URL string.

Method Details

__construct() public method

### Options - _ext - Defines the extensions used for this route. - pass - Copies the listed parameters into params['pass'].
public __construct ( string $template, array | string $defaults = [], array $options = [] )
$template string Template string with parameter placeholders
$defaults array | string Defaults for the route.
$options array Array of additional options for the Route

__set_state() public static method

This method helps for applications that want to implement router caching.
public static __set_state ( array $fields ) : Route
$fields array Key/Value of object attributes
return Route A new instance of the route

_matchMethod() protected method

Check whether or not the URL's HTTP method matches.
protected _matchMethod ( array $url ) : boolean
$url array The array for the URL being generated.
return boolean

_parseArgs() protected method

Return true if a given named $param's $val matches a given $rule depending on $context. Currently implemented rule types are controller, action and match that can be combined with each other.
protected _parseArgs ( string $args, string $context ) : array
$args string A string with the passed params. eg. /1/foo
$context string The current route context, which should contain controller/action keys.
return array Array of passed args.

_parseExtension() protected method

If no registered extension is found, no extension is returned and the URL is returned unmodified.
protected _parseExtension ( string $url ) : array
$url string The url to parse.
return array containing url, extension

_persistParams() protected method

Apply persistent parameters to a URL array. Persistent parameters are a special key used during route creation to force route parameters to persist when omitted from a URL array.
protected _persistParams ( array $url, array $params ) : array
$url array The array to apply persistent parameters to.
$params array An array of persistent values to replace persistent ones.
return array An array with persistent parameters applied.

_writeRoute() protected method

Uses the template, defaults and options properties to compile a regular expression that can be used to parse request strings.
protected _writeRoute ( ) : void
return void

_writeUrl() protected method

Composes the string URL using the template used to create the route.
protected _writeUrl ( array $params, array $pass = [], array $query = [] ) : string
$params array The params to convert to a string url
$pass array The additional passed arguments
$query array An array of parameters
return string Composed route string.

compile() public method

Modifies defaults property so all necessary keys are set and populates $this->names with the named routing elements.
public compile ( ) : array
return array Returns a string regular expression of the compiled route.

compiled() public method

Check if a Route has been compiled into a regular expression.
public compiled ( ) : boolean
return boolean

extensions() public method

Get/Set the supported extensions for this route.
Deprecation: 3.3.9 Use getExtensions/setExtensions instead.
public extensions ( null | string | array $extensions = null ) : array | null
$extensions null | string | array The extensions to set. Use null to get.
return array | null The extensions or null.

getExtensions() public method

Get the supported extensions for this route.
public getExtensions ( ) : array
return array

getName() public method

Get the standardized plugin.controller:action name for a route.
public getName ( ) : string
return string

match() public method

If the URL matches the route parameters and settings, then return a generated string URL. If the URL doesn't match the route parameters, false will be returned. This method handles the reverse routing or conversion of URL arrays into string URLs.
public match ( array $url, array $context = [] ) : string | false
$url array An array of parameters to check matching with.
$context array An array of the current request context. Contains information such as the current host, scheme, port, base directory and other url params.
return string | false Either a string URL for the parameters if they match or false.

parse() public method

If the route can be parsed an array of parameters will be returned; if not false will be returned. String URLs are parsed if they match a routes regular expression.
public parse ( string $url, string $method = '' ) : array | false
$url string The URL to attempt to parse.
$method string The HTTP method of the request being parsed.
return array | false An array of request parameters, or false on failure.

setExtensions() public method

Set the supported extensions for this route.
public setExtensions ( array $extensions )
$extensions array The extensions to set.

staticPath() public method

Get the static path portion for this route.
public staticPath ( ) : string
return string

Property Details

$_compiledRoute protected property

The compiled route regular expression
protected string $_compiledRoute
return string

$_extensions protected property

List of connected extensions for this route.
protected array $_extensions
return array

$_greedy protected property

Is this route a greedy route? Greedy routes have a /* in their template
protected string $_greedy
return string

$_name protected property

The name for a route. Fetch with Route::getName();
protected string $_name
return string

$defaults public property

Default parameters for a Route
public array $defaults
return array

$keys public property

/:controller/:action/:id has 3 key elements
public array $keys
return array

$options public property

An array of additional parameters for the Route.
public array $options
return array

$template public property

The routes template string.
public string $template
return string