Browse Source

Enable `UrlNormalizer` in `UrlManger` by default

tags/3.0.0-alpha1
Robert Korulczyk 8 years ago
parent
commit
a77749a6a1
  1. 8
      framework/UPGRADE.md
  2. 19
      framework/web/UrlManager.php
  3. 2
      framework/web/UrlRule.php
  4. 1
      tests/framework/web/UrlRuleTest.php

8
framework/UPGRADE.md

@ -37,13 +37,15 @@ Upgrade to Yii 2.1.0
* `yii\filters\AccessControl` has been optimized by only instantiating rules at the moment of use.
This could lead to a potential BC-break if you are depending on $rules to be instantiated in init().
Upgrade from Yii 2.0.8
----------------------
* Method `yii\web\Request::getBodyParams()` has been changed to pass full value of 'content-type' header to the second
argument of `yii\web\RequestParserInterface::parse()`. If you create your own custom parser, which relies on `$contentType`
argument, ensure to process it correctly as it may content additional data.
* `yii\web\UrlNormalizer` is now enabled by default in `yii\web\UrlManager`.
If you are using `yii\web\Request::resolve()` or `yii\web\UrlManager::parseRequest()` directly,
make sure all potential exceptions are handled correctly.
Upgrade from Yii 2.0.8
----------------------

19
framework/web/UrlManager.php

@ -127,22 +127,11 @@ class UrlManager extends Component
*/
public $ruleConfig = ['class' => UrlRule::class];
/**
* @var UrlNormalizer|array|string|false the configuration for [[UrlNormalizer]] used by this UrlManager.
* The default value is `false`, which means normalization will be skipped.
* If you wish to enable URL normalization, you should configure this property manually.
* For example:
*
* ```php
* [
* 'class' => 'yii\web\UrlNormalizer',
* 'collapseSlashes' => true,
* 'normalizeTrailingSlash' => true,
* ]
* ```
*
* @var UrlNormalizer|array|false the configuration for [[UrlNormalizer]] used by this UrlManager.
* If `false` normalization will be skipped.
* @since 2.0.10
*/
public $normalizer = false;
public $normalizer = ['class' => UrlNormalizer::class];
/**
* @var string the cache key for cached rules
@ -164,7 +153,7 @@ class UrlManager extends Component
parent::init();
if ($this->normalizer !== false) {
$this->normalizer = Instance::ensure($this->normalizer, UrlNormalizer::className());
$this->normalizer = Instance::ensure($this->normalizer, UrlNormalizer::class);
}
if (!$this->enablePrettyUrl || empty($this->rules)) {

2
framework/web/UrlRule.php

@ -139,7 +139,7 @@ class UrlRule extends Object implements UrlRuleInterface
throw new InvalidConfigException('UrlRule::route must be set.');
}
if (is_array($this->normalizer)) {
$normalizerConfig = array_merge(['class' => UrlNormalizer::className()], $this->normalizer);
$normalizerConfig = array_merge(['class' => UrlNormalizer::class], $this->normalizer);
$this->normalizer = Yii::createObject($normalizerConfig);
}
if ($this->normalizer !== null && $this->normalizer !== false && !$this->normalizer instanceof UrlNormalizer) {

1
tests/framework/web/UrlRuleTest.php

@ -64,7 +64,6 @@ class UrlRuleTest extends TestCase
{
$manager = new UrlManager([
'cache' => null,
'normalizer' => UrlNormalizer::class,
]);
$request = new Request(['hostInfo' => 'http://en.example.com']);
$suites = $this->getTestsForParseRequest();

Loading…
Cancel
Save