* @since 2.0 */ class ThemeManager extends ApplicationComponent { /** * default themes base path */ const DEFAULT_BASEPATH = 'themes'; /** * @var string the name of the theme class for representing a theme. * Defaults to {@link Theme}. This can also be a class name in dot syntax. */ public $themeClass = 'Theme'; /** * @var string the base path containing all themes. Defaults to '@entry/themes'. */ public $basePath = '@entry/themes'; /** * @var string the base URL for all themes. Defaults to "@www/themes". */ public $baseUrl = '@www/themes'; /** * @param string $name name of the theme to be retrieved * @return Theme the theme retrieved. Null if the theme does not exist. */ public function getTheme($name) { $themePath = $this->getBasePath() . DIRECTORY_SEPARATOR . $name; if (is_dir($themePath)) { $class = Yii::import($this->themeClass, true); return new $class($name, $themePath, $this->getBaseUrl() . '/' . $name); } else { return null; } } /** * @return array list of available theme names */ public function getThemeNames() { static $themes; if ($themes === null) { $themes = array(); $basePath = $this->getBasePath(); $folder = @opendir($basePath); while (($file = @readdir($folder)) !== false) { if ($file !== '.' && $file !== '..' && $file !== '.svn' && $file !== '.gitignore' && is_dir($basePath . DIRECTORY_SEPARATOR . $file)) { $themes[] = $file; } } closedir($folder); sort($themes); } return $themes; } }