Browse Source

Fixes #2303: Fixed the bug that `yii\base\Theme::pathMap` did not support dynamic update with path aliases

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
00f34f390a
  1. 1
      framework/CHANGELOG.md
  2. 25
      framework/base/Theme.php

1
framework/CHANGELOG.md

@ -41,6 +41,7 @@ Yii Framework 2 Change Log
- Bug #2091: `QueryBuilder::buildInCondition()` fails to handle array not starting with index 0 (qiangxue)
- Bug #2160: SphinxQL does not support OFFSET (qiangxue, romeo7)
- Bug #2212: `yii\gridview\DataColumn` generates incorrect labels when used with nosql DB and there is no data (qiangxue)
- Bug #2303: Fixed the bug that `yii\base\Theme::pathMap` did not support dynamic update with path aliases (qiangxue)
- Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark)
- Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark)
- Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)

25
framework/base/Theme.php

@ -93,6 +93,13 @@ class Theme extends Component
public function init()
{
parent::init();
if ($this->baseUrl === null) {
throw new InvalidConfigException('The "baseUrl" property must be set.');
} else {
$this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/');
}
if (empty($this->pathMap)) {
if ($this->basePath !== null) {
$this->basePath = Yii::getAlias($this->basePath);
@ -101,20 +108,6 @@ class Theme extends Component
throw new InvalidConfigException('The "basePath" property must be set.');
}
}
$paths = [];
foreach ($this->pathMap as $from => $tos) {
$from = FileHelper::normalizePath(Yii::getAlias($from));
foreach ((array)$tos as $to) {
$to = FileHelper::normalizePath(Yii::getAlias($to));
$paths[$from . DIRECTORY_SEPARATOR][] = $to . DIRECTORY_SEPARATOR;
}
}
$this->pathMap = $paths;
if ($this->baseUrl === null) {
throw new InvalidConfigException('The "baseUrl" property must be set.');
} else {
$this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/');
}
}
/**
@ -127,9 +120,11 @@ class Theme extends Component
{
$path = FileHelper::normalizePath($path);
foreach ($this->pathMap as $from => $tos) {
$from = FileHelper::normalizePath(Yii::getAlias($from)) . DIRECTORY_SEPARATOR;
if (strpos($path, $from) === 0) {
$n = strlen($from);
foreach ($tos as $to) {
foreach ((array)$tos as $to) {
$to = FileHelper::normalizePath(Yii::getAlias($to)) . DIRECTORY_SEPARATOR;
$file = $to . substr($path, $n);
if (is_file($file)) {
return $file;

Loading…
Cancel
Save