From f351697c482ddd013bb521b704734ed87a1aec2b Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Wed, 19 Nov 2014 17:45:57 +1100 Subject: [PATCH] Streamline Theme object API (::load should be static as in CmsObject) --- modules/cms/classes/Theme.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/modules/cms/classes/Theme.php b/modules/cms/classes/Theme.php index 43040f319..6e1c3dafc 100644 --- a/modules/cms/classes/Theme.php +++ b/modules/cms/classes/Theme.php @@ -47,10 +47,13 @@ class Theme /** * Loads the theme. + * @return self */ - public function load($dirName) + public static function load($dirName) { - $this->dirName = $dirName; + $theme = new static; + $theme->setDirName($dirName); + return $theme; } /** @@ -67,6 +70,15 @@ class Theme return base_path().Config::get('cms.themesDir').'/'.$dirName; } + /** + * Sets the theme directory name. + * @return void + */ + public function setDirName($dirName) + { + $this->dirName = $dirName; + } + /** * Returns the theme directory name. * @return string @@ -135,8 +147,8 @@ class Theme throw new SystemException(Lang::get('cms::lang.theme.active.not_set')); } - $theme = new static; - $theme->load($activeTheme); + $theme = static::load($activeTheme); + if (!File::isDirectory($theme->getPath())) { return self::$activeThemeCache = null; } @@ -184,8 +196,8 @@ class Theme throw new SystemException(Lang::get('cms::lang.theme.edit.not_set')); } - $theme = new static; - $theme->load($editTheme); + $theme = static::load($editTheme); + if (!File::isDirectory($theme->getPath())) { return self::$editThemeCache = null; } @@ -210,8 +222,8 @@ class Theme continue; } - $theme = new static; - $theme->load($fileinfo->getFilename()); + $theme = static::load($fileinfo->getFilename()); + $result[] = $theme; }