Class yii\web\UrlNormalizer

Inheritanceyii\web\UrlNormalizer » yii\base\BaseObject
Implementsyii\base\Configurable
Available since version2.0.10
Source Code https://github.com/yiisoft/yii2/blob/master/framework/web/UrlNormalizer.php

UrlNormalizer normalizes URLs for yii\web\UrlManager and yii\web\UrlRule.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$action integer|callable|null Action to perform during route normalization. yii\web\UrlNormalizer
$collapseSlashes boolean Whether slashes should be collapsed, for example site///index will be converted into site/index yii\web\UrlNormalizer
$normalizeTrailingSlash boolean Whether trailing slash should be normalized according to the suffix settings of the rule yii\web\UrlNormalizer

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
normalizePathInfo() Normalizes specified pathInfo. yii\web\UrlNormalizer
normalizeRoute() Performs normalization action for the specified $route. yii\web\UrlNormalizer

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
collapseSlashes() Collapse consecutive slashes in $pathInfo, for example converts site///index into site/index. yii\web\UrlNormalizer
normalizeTrailingSlash() Adds or removes trailing slashes from $pathInfo depending on whether the $suffix has a trailing slash or not. yii\web\UrlNormalizer

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
ACTION_NOT_FOUND 404 Represents showing 404 error page during route normalization. yii\web\UrlNormalizer
ACTION_REDIRECT_PERMANENT 301 Represents permament redirection during route normalization. yii\web\UrlNormalizer
ACTION_REDIRECT_TEMPORARY 302 Represents temporary redirection during route normalization. yii\web\UrlNormalizer

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 - yii\web\NotFoundHttpException will be thrown
  • callable - custom user callback, for example:

    function ($route, $normalizer) {
        // use custom action for redirections
        $route[1]['oldRoute'] = $route[0];
        $route[0] = 'site/redirect';
        return $route;
    }
    
public integer|callable|null $action self::ACTION_REDIRECT_PERMANENT
$collapseSlashes public property

Whether slashes should be collapsed, for example site///index will be converted into site/index

public boolean $collapseSlashes true
$normalizeTrailingSlash public property

Whether trailing slash should be normalized according to the suffix settings of the rule

Method Details

collapseSlashes() protected method

Collapse consecutive slashes in $pathInfo, for example converts site///index into site/index.

protected string collapseSlashes ( $pathInfo )
$pathInfo string

Raw path info.

return string

Normalized path info.

normalizePathInfo() public method

Normalizes specified pathInfo.

public string normalizePathInfo ( $pathInfo, $suffix, &$normalized false )
$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 array normalizeRoute ( $route )
$route array

Route for normalization

return array

Normalized route

throws yii\base\InvalidConfigException

if invalid normalization action is used.

throws yii\web\UrlNormalizerRedirectException

if normalization requires redirection.

throws yii\web\NotFoundHttpException

if normalization suggests action matching route does not exist.

normalizeTrailingSlash() protected method

Adds or removes trailing slashes from $pathInfo depending on whether the $suffix has a trailing slash or not.

protected string normalizeTrailingSlash ( $pathInfo, $suffix )
$pathInfo string

Raw path info.

$suffix string
return string

Normalized path info.