Yii2 framework backup
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

13 years ago
<?php
/**
* Theme class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\base;
/**
* Theme represents an application theme.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Theme extends ApplicationComponent
{
13 years ago
public $basePath;
public $baseUrl;
13 years ago
13 years ago
public function init()
13 years ago
{
13 years ago
if ($this->basePath !== null) {
13 years ago
$this->basePath = \Yii::getAlias($this->basePath, true);
13 years ago
} else {
throw new Exception("Theme.basePath must be set.");
}
if ($this->baseUrl !== null) {
13 years ago
$this->baseUrl = \Yii::getAlias($this->baseUrl, true);
13 years ago
} else {
throw new Exception("Theme.baseUrl must be set.");
}
13 years ago
}
/**
13 years ago
* @param Application|Module|Controller|Object $context
13 years ago
* @return string
13 years ago
*/
13 years ago
public function getViewPath($context = null)
13 years ago
{
13 years ago
$viewPath = $this->basePath . DIRECTORY_SEPARATOR . 'views';
if ($context === null || $context instanceof Application) {
return $viewPath;
} elseif ($context instanceof Controller || $context instanceof Module) {
return $viewPath . DIRECTORY_SEPARATOR . $context->getUniqueId();
} else {
return $viewPath . DIRECTORY_SEPARATOR . str_replace('\\', '_', get_class($context));
}
13 years ago
}
/**
13 years ago
* @param Module $module
* @return string
13 years ago
*/
13 years ago
public function getLayoutPath($module = null)
13 years ago
{
13 years ago
return $this->getViewPath($module) . DIRECTORY_SEPARATOR . 'layouts';
13 years ago
}
}