Browse Source

Enable `UrlNormalizer` in `UrlManger` by default

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

44
framework/UPGRADE.md

@ -34,16 +34,18 @@ Upgrade to Yii 2.1.0
`yii\db\QueryBuilderbuild::buildOrderByAndLimit($sql, $orderBy, $limit, $offset)` -> `buildOrderByAndLimit($sql, $orderBy, $limit, $offset, &$params)`
`yii\widgets\ActiveField::hint($content = null, $options = [])`
* `yii\filters\AccessControl` has been optimized by only instantiating rules at the moment of use.
* `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
----------------------
@ -101,7 +103,7 @@ Upgrade from Yii 2.0.6
* The context of `yii.confirm` JavaScript function was changed from `yii` object to the DOM element which triggered
the event.
- If you overrode the `yii.confirm` function and accessed the `yii` object through `this`, you must access it
with global variable `yii` instead.
@ -147,7 +149,7 @@ Upgrade from Yii 2.0.3
* Updated dependency to `cebe/markdown` to version `1.1.x`.
If you need stick with 1.0.x, you can specify that in your `composer.json` by
adding the following line in the `require` section:
```json
"cebe/markdown": "~1.0.0",
```
@ -174,7 +176,7 @@ Upgrade from Yii 2.0.0
* Upgraded Twitter Bootstrap to [version 3.3.x](http://blog.getbootstrap.com/2014/10/29/bootstrap-3-3-0-released/).
If you need to use an older version (i.e. stick with 3.2.x) you can specify that in your `composer.json` by
adding the following line in the `require` section:
```json
"bower-asset/bootstrap": "3.2.*",
```
@ -189,13 +191,13 @@ Upgrade from Yii 2.0 RC
This causes trouble because the formatter uses `Yii::$app->timeZone` as the default values for output so no timezone conversion
was possible. If your timestamps are stored in the database without a timezone identifier you have to ensure they are in UTC or
add a timezone identifier explicitly.
* `yii\bootstrap\Collapse` is now encoding labels by default. `encode` item option and global `encodeLabels` property were
introduced to disable it. Keys are no longer used as labels. You need to remove keys and use `label` item option instead.
* The `yii\base\View::beforeRender()` and `yii\base\View::afterRender()` methods have two extra parameters `$viewFile`
and `$params`. If you are overriding these methods, you should adjust the method signature accordingly.
* If you've used `asImage` formatter i.e. `Yii::$app->formatter->asImage($value, $alt);` you should change it
to `Yii::$app->formatter->asImage($value, ['alt' => $alt]);`.
@ -227,9 +229,9 @@ Upgrade from Yii 2.0 Beta
}
}
```
It is also a good idea to upgrade composer itself to the latest version if you see any problems:
```
php composer.phar self-update
```
@ -321,7 +323,7 @@ Upgrade from Yii 2.0 Beta
doesn't have `cookieValidationKey` property.
* `yii\rbac\PhpManager` now stores data in three separate files instead of one. In order to convert old file to
new ones save the following code as `convert.php` that should be placed in the same directory your `rbac.php` is in:
new ones save the following code as `convert.php` that should be placed in the same directory your `rbac.php` is in:
```php
<?php
@ -329,16 +331,16 @@ new ones save the following code as `convert.php` that should be placed in the s
$itemsFile = 'items.php';
$assignmentsFile = 'assignments.php';
$rulesFile = 'rules.php';
$oldData = include $oldFile;
function saveToFile($data, $fileName) {
$out = var_export($data, true);
$out = "<?php\nreturn " . $out . ';';
$out = str_replace(['array (', ')'], ['[', ']'], $out);
file_put_contents($fileName, $out);
}
$items = [];
$assignments = [];
if (isset($oldData['items'])) {
@ -352,16 +354,16 @@ new ones save the following code as `convert.php` that should be placed in the s
$items[$name] = $data;
}
}
$rules = [];
if (isset($oldData['rules'])) {
$rules = $oldData['rules'];
}
saveToFile($items, $itemsFile);
saveToFile($assignments, $assignmentsFile);
saveToFile($rules, $rulesFile);
echo "Done!\n";
```
@ -396,7 +398,7 @@ new ones save the following code as `convert.php` that should be placed in the s
}, $duration, $dependency);
```
* Due to significant changes to security you need to upgrade your code to use `\yii\base\Security` component instead of
helper. If you have any data encrypted it should be re-encrypted. In order to do so you can use old security helper
[as explained by @docsolver at github](https://github.com/yiisoft/yii2/issues/4461#issuecomment-50237807).
@ -493,6 +495,6 @@ new ones save the following code as `convert.php` that should be placed in the s
* The signature of `View::registerJsFile()` and `View::registerCssFile()` has changed. The `$depends` and `$position`
paramaters have been merged into `$options`. The new signatures are as follows:
- `registerJsFile($url, $options = [], $key = null)`
- `registerCssFile($url, $options = [], $key = null)`

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