From 15b93c7b0389e157c5760249787b5e870776fa93 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Sat, 19 Jul 2014 16:09:44 +1000 Subject: [PATCH] Rewind DI to prevent double up bug --- modules/cms/classes/Theme.php | 15 +++++++-------- tests/unit/cms/classes/ThemeTest.php | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/cms/classes/Theme.php b/modules/cms/classes/Theme.php index 83bcd0dc2..d53d5ad9a 100644 --- a/modules/cms/classes/Theme.php +++ b/modules/cms/classes/Theme.php @@ -68,7 +68,7 @@ class Theme */ public static function exists($dirName) { - $theme = new self; + $theme = new static; $path = $theme->getPath($dirName); return File::isDirectory($path); @@ -112,7 +112,7 @@ class Theme if (!strlen($activeTheme)) throw new SystemException(Lang::get('cms::lang.theme.active.not_set')); - $theme = new self(); + $theme = new static; $theme->load($activeTheme); if (!File::isDirectory($theme->getPath())) return null; @@ -154,7 +154,7 @@ class Theme if (!strlen($editTheme)) throw new SystemException(Lang::get('cms::lang.theme.edit.not_set')); - $theme = new self(); + $theme = new static; $theme->load($editTheme); if (!File::isDirectory($theme->getPath())) return null; @@ -171,17 +171,16 @@ class Theme $path = base_path().Config::get('cms.themesDir'); $it = new DirectoryIterator($path); + $it->rewind(); + $result = []; foreach ($it as $fileinfo) { - if ($fileinfo->isDot() ||(substr($fileinfo->getFilename(), 0, 1) == '.')) + if ($fileinfo->isDot() || (substr($fileinfo->getFilename(), 0, 1) == '.')) continue; - $theme = new self(); + $theme = new static; $theme->load($fileinfo->getFilename()); - $result[] = $theme; - - } return $result; diff --git a/tests/unit/cms/classes/ThemeTest.php b/tests/unit/cms/classes/ThemeTest.php index 436f033ae..28ae2fe63 100644 --- a/tests/unit/cms/classes/ThemeTest.php +++ b/tests/unit/cms/classes/ThemeTest.php @@ -17,7 +17,7 @@ class ThemeTest extends TestCase $it->setMaxDepth(1); $it->rewind(); - while($it->valid()) { + while ($it->valid()) { if (!$it->isDot() && !$it->isDir() && $it->getExtension() == 'htm') $result++;