Commit 79b278c8 by Qiang Xue

refactored theme.

parent fc415b15
...@@ -33,11 +33,17 @@ use yii\helpers\FileHelper; ...@@ -33,11 +33,17 @@ use yii\helpers\FileHelper;
class Theme extends Component class Theme extends Component
{ {
/** /**
* @var string the root path of this theme. * @var string the root path or path alias of this theme. All resources of this theme are located
* under this directory. This property must be set if [[pathMap]] is not set.
* @see pathMap * @see pathMap
*/ */
public $basePath; public $basePath;
/** /**
* @var string the base URL (or path alias) for this theme. All resources of this theme are considered
* to be under this base URL. This property must be set. It is mainly used by [[getUrl()]].
*/
public $baseUrl;
/**
* @var array the mapping between view directories and their corresponding themed versions. * @var array the mapping between view directories and their corresponding themed versions.
* If not set, it will be initialized as a mapping from [[Application::basePath]] to [[basePath]]. * If not set, it will be initialized as a mapping from [[Application::basePath]] to [[basePath]].
* This property is used by [[applyTo()]] when a view is trying to apply the theme. * This property is used by [[applyTo()]] when a view is trying to apply the theme.
...@@ -45,7 +51,6 @@ class Theme extends Component ...@@ -45,7 +51,6 @@ class Theme extends Component
*/ */
public $pathMap; public $pathMap;
private $_baseUrl;
/** /**
* Initializes the theme. * Initializes the theme.
...@@ -69,25 +74,11 @@ class Theme extends Component ...@@ -69,25 +74,11 @@ class Theme extends Component
$paths[$from . DIRECTORY_SEPARATOR] = $to . DIRECTORY_SEPARATOR; $paths[$from . DIRECTORY_SEPARATOR] = $to . DIRECTORY_SEPARATOR;
} }
$this->pathMap = $paths; $this->pathMap = $paths;
if ($this->baseUrl === null) {
throw new InvalidConfigException("Theme::baseUrl must be set.");
} else {
$this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/');
} }
/**
* Returns the base URL for this theme.
* The method [[getUrl()]] will prefix this to the given URL.
* @return string the base URL for this theme.
*/
public function getBaseUrl()
{
return $this->_baseUrl;
}
/**
* Sets the base URL for this theme.
* @param string $value the base URL for this theme.
*/
public function setBaseUrl($value)
{
$this->_baseUrl = rtrim(Yii::getAlias($value), '/');
} }
/** /**
...@@ -112,7 +103,7 @@ class Theme extends Component ...@@ -112,7 +103,7 @@ class Theme extends Component
} }
/** /**
* Converts a relative URL into an absolute URL using [[basePath]]. * Converts a relative URL into an absolute URL using [[baseUrl]].
* @param string $url the relative URL to be converted. * @param string $url the relative URL to be converted.
* @return string the absolute URL * @return string the absolute URL
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment