Documentation

Helper
in package

Methods that may be useful for processing routing activity

Tags
author

Alexey Bobkov, Samuel Georges

Table of Contents

getParameterName()  : string
Extracts the parameter name from a URL pattern segment definition.
getSegmentDefaultValue()  : string
Extracts the default parameter value from a URL pattern segment definition.
getSegmentRegExp()  : string
Extracts the regular expression from a URL pattern segment definition.
normalizeUrl()  : string
Adds leading slash and removes trailing slash from the URL.
parseValues()  : string
Replaces :column_name with it's object value. Example: /some/link/:id/:name -> /some/link/1/Joe
rebuildUrl()  : string
Rebuilds a URL from an array of segments.
replaceParameters()  : string
Replaces :column_name with object value without requiring a list of names. Example: /some/link/:id/:name -> /some/link/1/Joe
segmentIsOptional()  : bool
Checks whether an URL pattern segment is optional.
segmentIsWildcard()  : bool
Checks whether an URL pattern segment is a wildcard.
segmentizeUrl()  : array<string|int, mixed>
Splits an URL by segments separated by the slash symbol.

Methods

getParameterName()

Extracts the parameter name from a URL pattern segment definition.

public static getParameterName(string $segment) : string
Parameters
$segment : string

The segment definition.

Return values
string —

Returns the segment name.

getSegmentDefaultValue()

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

public static getSegmentDefaultValue(string $segment) : string
Parameters
$segment : string

The segment definition.

Return values
string —

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

getSegmentRegExp()

Extracts the regular expression from a URL pattern segment definition.

public static getSegmentRegExp(string $segment) : string
Parameters
$segment : string

The segment definition.

Return values
string —

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

normalizeUrl()

Adds leading slash and removes trailing slash from the URL.

public static normalizeUrl(string $url) : string
Parameters
$url : string

URL to normalize.

Return values
string —

Returns normalized URL.

parseValues()

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

public static parseValues(stdObject $object, array<string|int, mixed> $columns, string $string) : string
Parameters
$object : stdObject

Object containing the data

$columns : array<string|int, mixed>

Expected key names to parse

$string : string

URL template

Return values
string —

Built string

rebuildUrl()

Rebuilds a URL from an array of segments.

public static rebuildUrl(array<string|int, mixed> $urlArray) : string
Parameters
$urlArray : array<string|int, mixed>

Array the URL segments.

Return values
string —

Returns rebuilt URL.

replaceParameters()

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

public static replaceParameters(stdObject $object, string $string) : string
Parameters
$object : stdObject

Object containing the data

$string : string

URL template

Return values
string —

Built string

segmentIsOptional()

Checks whether an URL pattern segment is optional.

public static segmentIsOptional(string $segment) : bool
Parameters
$segment : string

The segment definition.

Return values
bool —

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

segmentIsWildcard()

Checks whether an URL pattern segment is a wildcard.

public static segmentIsWildcard(string $segment) : bool
Parameters
$segment : string

The segment definition.

Return values
bool —

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

segmentizeUrl()

Splits an URL by segments separated by the slash symbol.

public static segmentizeUrl(string $url) : array<string|int, mixed>
Parameters
$url : string

URL to segmentize.

Return values
array<string|int, mixed> —

Returns the URL segments.

Search results