mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-16 06:17:56 +08:00
Fixes #10475: Extracted getUrlFromCache() and setRuleToCache() protected methods from yii\web\UrlManager::createUrl()
This commit is contained in:
committed by
Alexander Makarov
parent
5dab713840
commit
f75f453ec4
@@ -59,6 +59,7 @@ Yii Framework 2 Change Log
|
|||||||
- Enh #9893: `yii.js` handleAction enhanced to support for data-form attribute, so links can trigger specific forms (SamMousa)
|
- Enh #9893: `yii.js` handleAction enhanced to support for data-form attribute, so links can trigger specific forms (SamMousa)
|
||||||
- Enh #10322: ActiveForm now respects formtarget attribute of submit button (AnatolyRugalev)
|
- Enh #10322: ActiveForm now respects formtarget attribute of submit button (AnatolyRugalev)
|
||||||
- Enh #10451: Check of existence of `$_SERVER` in `\yii\web\Request` before using it (quantum13)
|
- Enh #10451: Check of existence of `$_SERVER` in `\yii\web\Request` before using it (quantum13)
|
||||||
|
- Enh #10475: Extracted `getUrlFromCache()` and `setRuleToCache()` protected methods from `yii\web\UrlManager::createUrl()` (dmdark)
|
||||||
- Enh #10487: `yii\helpers\BaseArrayHelper::index()` got a third parameter `$groupBy` to group the input array by the key in one or more dimensions (quantum13, silverfire, samdark)
|
- Enh #10487: `yii\helpers\BaseArrayHelper::index()` got a third parameter `$groupBy` to group the input array by the key in one or more dimensions (quantum13, silverfire, samdark)
|
||||||
- Enh #10610: Added `BaseUrl::$urlManager` to be able to set URL manager used for creating URLs (samdark)
|
- Enh #10610: Added `BaseUrl::$urlManager` to be able to set URL manager used for creating URLs (samdark)
|
||||||
- Enh #10631: Splitted gettng label and rendering cell in `yii\grid\DataColumn::renderHeaderCellContent()` to make code simpler (t-kanstantsin, samdark)
|
- Enh #10631: Splitted gettng label and rendering cell in `yii\grid\DataColumn::renderHeaderCellContent()` to make code simpler (t-kanstantsin, samdark)
|
||||||
|
|||||||
@@ -322,28 +322,19 @@ class UrlManager extends Component
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @var $rule UrlRule */
|
$url = $this->getUrlFromCache($cacheKey, $route, $params);
|
||||||
$url = false;
|
|
||||||
if (isset($this->_ruleCache[$cacheKey])) {
|
|
||||||
foreach ($this->_ruleCache[$cacheKey] as $rule) {
|
|
||||||
if (($url = $rule->createUrl($this, $route, $params)) !== false) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->_ruleCache[$cacheKey] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($url === false) {
|
if ($url === false) {
|
||||||
$cacheable = true;
|
$cacheable = true;
|
||||||
foreach ($this->rules as $rule) {
|
foreach ($this->rules as $rule) {
|
||||||
|
/* @var $rule UrlRule */
|
||||||
if (!empty($rule->defaults) && $rule->mode !== UrlRule::PARSING_ONLY) {
|
if (!empty($rule->defaults) && $rule->mode !== UrlRule::PARSING_ONLY) {
|
||||||
// if there is a rule with default values involved, the matching result may not be cached
|
// if there is a rule with default values involved, the matching result may not be cached
|
||||||
$cacheable = false;
|
$cacheable = false;
|
||||||
}
|
}
|
||||||
if (($url = $rule->createUrl($this, $route, $params)) !== false) {
|
if (($url = $rule->createUrl($this, $route, $params)) !== false) {
|
||||||
if ($cacheable) {
|
if ($cacheable) {
|
||||||
$this->_ruleCache[$cacheKey][] = $rule;
|
$this->setRuleToCache($cacheKey, $rule);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -380,6 +371,41 @@ class UrlManager extends Component
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get URL from internal cache if exists
|
||||||
|
* @param string $cacheKey generated cache key to store data.
|
||||||
|
* @param string $route the route (e.g. `site/index`).
|
||||||
|
* @param array $params rule params.
|
||||||
|
* @return bool|string the created URL
|
||||||
|
* @see createUrl()
|
||||||
|
* @since 2.0.8
|
||||||
|
*/
|
||||||
|
protected function getUrlFromCache($cacheKey, $route, $params)
|
||||||
|
{
|
||||||
|
if (!empty($this->_ruleCache[$cacheKey])) {
|
||||||
|
foreach ($this->_ruleCache[$cacheKey] as $rule) {
|
||||||
|
/* @var $rule UrlRule */
|
||||||
|
if (($url = $rule->createUrl($this, $route, $params)) !== false) {
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->_ruleCache[$cacheKey] = [];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store rule (e.g. [[UrlRule]]) to internal cache
|
||||||
|
* @param $cacheKey
|
||||||
|
* @param UrlRuleInterface $rule
|
||||||
|
* @since 2.0.8
|
||||||
|
*/
|
||||||
|
protected function setRuleToCache($cacheKey, UrlRuleInterface $rule)
|
||||||
|
{
|
||||||
|
$this->_ruleCache[$cacheKey][] = $rule;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an absolute URL using the given route and query parameters.
|
* Creates an absolute URL using the given route and query parameters.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user