diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 5efef88..6048a1c 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -14,6 +14,7 @@ Yii Framework 2 Change Log - Bug #17828: Fix `yii\web\UploadedFile::saveAs()` failing when error value in `$_FILES` entry is a string (haveyaseen) - Bug #17829: `yii\helpers\ArrayHelper::filter` now correctly filters data when passing a filter with more than 2 levels (rhertogh) - Enh #7622: Allow `yii\data\ArrayDataProvider` to control the sort flags for `sortModels` through `yii\data\Sort::sortFlags` property (askobara) +- Enh #16721: Use `Instance::ensure()` to initialize `UrlManager::$cache` (rob006) - Bug #17863: `\yii\helpers\BaseInflector::slug()` doesn't work with an empty string as a replacement argument (haruatari) - Bug #17881: `yii\db\Query::queryScalar()` wasn’t reverting the `select`, `orderBy`, `limit`, and `offset` params if an exception occurred (brandonkelly) - Bug #17875: Use `move_uploaded_file()` function instead of `copy()` and `unlink()` for saving uploaded files in case of POST request (sup-ham) diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index d7e8022..aa550ce 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -101,6 +101,10 @@ Upgrade from Yii 2.0.32 * `UploadedFile` class `deleteTempFile()` and `isUploadedFile()` methods introduced in 2.0.32 were removed. +* Exception will be thrown if `UrlManager::$cache` configuration is incorrect (previously misconfiguration was silently + ignored and `UrlManager` continue to work without cache). Make sure that `UrlManager::$cache` is correctly configured + or set it to `null` to explicitly disable cache. + Upgrade from Yii 2.0.31 ----------------------- diff --git a/framework/web/UrlManager.php b/framework/web/UrlManager.php index 88d6b0e..30fa865 100644 --- a/framework/web/UrlManager.php +++ b/framework/web/UrlManager.php @@ -11,6 +11,7 @@ use Yii; use yii\base\Component; use yii\base\InvalidConfigException; use yii\caching\CacheInterface; +use yii\di\Instance; use yii\helpers\Url; /** @@ -118,12 +119,14 @@ class UrlManager extends Component */ public $routeParam = 'r'; /** - * @var CacheInterface|string the cache object or the application component ID of the cache object. + * @var CacheInterface|array|string the cache object or the application component ID of the cache object. + * This can also be an array that is used to create a [[CacheInterface]] instance in case you do not want to use + * an application component. * Compiled URL rules will be cached through this cache object, if it is available. * * After the UrlManager object is created, if you want to change this property, * you should only assign it with a cache object. - * Set this property to `false` if you do not want to cache the URL rules. + * Set this property to `false` or `null` if you do not want to cache the URL rules. * * Cache entries are stored for the time set by [[\yii\caching\Cache::$defaultDuration|$defaultDuration]] in * the cache configuration, which is unlimited by default. You may want to tune this value if your [[rules]] @@ -182,8 +185,8 @@ class UrlManager extends Component if (!$this->enablePrettyUrl) { return; } - if (is_string($this->cache)) { - $this->cache = Yii::$app->get($this->cache, false); + if ($this->cache !== false && $this->cache !== null) { + $this->cache = Instance::ensure($this->cache, 'yii\caching\CacheInterface'); } if (empty($this->rules)) { return;