PHP Class yii\web\UrlNormalizer

Since: 2.0.10
Author: Robert Korulczyk ([email protected])
Author: Cronfy ([email protected])
Inheritance: extends yii\base\Object
Show file Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$action action to perform during route normalization. Available options are: - null - no special action will be performed - 301 - the request should be redirected to the normalized URL using permanent redirection - 302 - the request should be redirected to the normalized URL using temporary redirection - 404 - NotFoundHttpException will be thrown - callable - custom user callback, for example: php function ($route, $normalizer) { use custom action for redirections $route[1]['oldRoute'] = $route[0]; $route[0] = 'site/redirect'; return $route; }
$collapseSlashes whether slashes should be collapsed, for example site///index will be converted into site/index
$normalizeTrailingSlash whether trailing slash should be normalized according to the suffix settings of the rule

Public Methods

Method Description
normalizePathInfo ( string $pathInfo, string $suffix, boolean &$normalized = false ) : string Normalizes specified pathInfo.
normalizeRoute ( array $route ) : array Performs normalization action for the specified $route.

Protected Methods

Method Description
collapseSlashes ( string $pathInfo ) : string Collapse consecutive slashes in $pathInfo, for example converts site///index into site/index.
normalizeTrailingSlash ( string $pathInfo, string $suffix ) : string Adds or removes trailing slashes from $pathInfo depending on whether the $suffix has a trailing slash or not.

Method Details

collapseSlashes() protected method

Collapse consecutive slashes in $pathInfo, for example converts site///index into site/index.
protected collapseSlashes ( string $pathInfo ) : string
$pathInfo string raw path info.
return string normalized path info.

normalizePathInfo() public method

Normalizes specified pathInfo.
public normalizePathInfo ( string $pathInfo, string $suffix, boolean &$normalized = false ) : string
$pathInfo string pathInfo for normalization
$suffix string current rule suffix
$normalized boolean if specified, this variable will be set to `true` if $pathInfo was changed during normalization
return string normalized pathInfo

normalizeRoute() public method

Performs normalization action for the specified $route.
public normalizeRoute ( array $route ) : array
$route array route for normalization
return array normalized route

normalizeTrailingSlash() protected method

Adds or removes trailing slashes from $pathInfo depending on whether the $suffix has a trailing slash or not.
protected normalizeTrailingSlash ( string $pathInfo, string $suffix ) : string
$pathInfo string raw path info.
$suffix string
return string normalized path info.

Property Details

$action public property

action to perform during route normalization. Available options are: - null - no special action will be performed - 301 - the request should be redirected to the normalized URL using permanent redirection - 302 - the request should be redirected to the normalized URL using temporary redirection - 404 - NotFoundHttpException will be thrown - callable - custom user callback, for example: php function ($route, $normalizer) { use custom action for redirections $route[1]['oldRoute'] = $route[0]; $route[0] = 'site/redirect'; return $route; }
public $action

$collapseSlashes public property

whether slashes should be collapsed, for example site///index will be converted into site/index
public $collapseSlashes

$normalizeTrailingSlash public property

whether trailing slash should be normalized according to the suffix settings of the rule
public $normalizeTrailingSlash