Helper

Methods that may be useful for processing routing activity

 class Winter\Storm\Router\Helper

Methods

public static getParameterName (string $segment) : string

Extracts the parameter name from a URL pattern segment definition.

Parameters
Property Description
$segment
string

The segment definition.

Returns
string

Returns the segment name.

public static getSegmentDefaultValue (string $segment) : string | false

Extracts the default parameter value from a URL pattern segment definition.

Parameters
Property Description
$segment
string

The segment definition.

Returns
string | false

Returns the default value if it is provided. Returns false otherwise.

public static getSegmentRegExp (string $segment) : string | false

Extracts the regular expression from a URL pattern segment definition.

Parameters
Property Description
$segment
string

The segment definition.

Returns
string | false

Returns the regular expression string or false if the expression is not defined.

public static normalizeUrl (string $url) : string

Adds leading slash and removes trailing slash from the URL.

Parameters
Property Description
$url
string

URL to normalize.

Returns
string

Returns normalized URL.

public static parseValues (object | array $object, array $columns, string $string) : string

Replaces :column_name with it's object value. Example: /some/link/:id/:name -> /some/link/1/Joe

Parameters
Property Description
$object
object | array

Object containing the data

$columns
array

Expected key names to parse

$string
string

URL template

Returns
string

Built string

public static rebuildUrl (array $urlArray) : string

Rebuilds a URL from an array of segments.

Parameters
Property Description
$urlArray
array

Array the URL segments.

Returns
string

Returns rebuilt URL.

public static replaceParameters (object | array $object, string $string) : string

Replaces :column_name with object value without requiring a list of names. Example: /some/link/:id/:name -> /some/link/1/Joe

Parameters
Property Description
$object
object | array

Object containing the data

$string
string

URL template

Returns
string

Built string

public static segmentIsOptional (string $segment) : bool

Checks whether an URL pattern segment is optional.

Parameters
Property Description
$segment
string

The segment definition.

Returns
bool

Returns boolean true if the segment is optional. Returns false otherwise.

public static segmentIsWildcard (string $segment) : bool

Checks whether an URL pattern segment is a wildcard.

Parameters
Property Description
$segment
string

The segment definition.

Returns
bool

Returns boolean true if the segment is a wildcard. Returns false otherwise.

public static segmentizeUrl (string $url) : array

Splits an URL by segments separated by the slash symbol.

Parameters
Property Description
$url
string

URL to segmentize.

Returns
array

Returns the URL segments.

Copyright © 2024 Winter CMS