From 95b2679f2074c5e42f6ddfebb27bc5c9117651e6 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 22 Feb 2017 23:39:56 +0100 Subject: [PATCH] renamed class property $classes to $foundClasses so it is clear that these classes has only been found but not yet loaded (require()). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- inc/loader/class_ClassLoader.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index ab7efc0b..7dd6d63e 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -58,9 +58,9 @@ class ClassLoader { private static $selfInstance = NULL; /** - * Array with all classes + * Array with all found classes */ - private $classes = array(); + private $foundClasses = array(); /** * List of loaded classes @@ -148,7 +148,7 @@ class ClassLoader { // Skip here if already cached if ($this->listCached === FALSE) { // Writes the cache file of our list away - $cacheContent = json_encode($this->classes); + $cacheContent = json_encode($this->foundClasses); file_put_contents($this->listCacheFQFN, $cacheContent); } // END - if @@ -156,7 +156,7 @@ class ClassLoader { if ($this->classesCached === FALSE) { // Generate a full-cache of all classes $cacheContent = ''; - foreach ($this->loadedClasses as $fqfn) { + foreach (array_keys($this->loadedClasses) as $fqfn) { // Load the file $cacheContent .= file_get_contents($fqfn); } // END - foreach @@ -255,7 +255,7 @@ class ClassLoader { $cacheContent = file_get_contents($this->listCacheFQFN); // And convert it - $this->classes = json_decode($cacheContent); + $this->foundClasses = json_decode($cacheContent); // List has been restored from cache! $this->listCached = TRUE; @@ -367,7 +367,7 @@ class ClassLoader { if ((substr($fileName, 0, strlen($this->prefix)) == $this->prefix) && (substr($fileName, -strlen($this->suffix), strlen($this->suffix)) == $this->suffix)) { // Add it to the list /* NOISY-DEBUG: */ printf('[%s:%d] ADD: %s,fqfn=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $fqfn); - $this->classes[$fileName] = $fqfn; + $this->foundClasses[$fileName] = $fqfn; } else { // Not added /* NOISY-DEBUG: */ printf('[%s:%d] NOT ADDED: %s,fqfn=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $fqfn); @@ -430,21 +430,21 @@ class ClassLoader { // Now look it up in our index /* NOISY-DEBUG: */ printf('[%s:%d] ISSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); - if ((isset($this->classes[$fileName])) && (!in_array($this->classes[$fileName], $this->loadedClasses))) { + if ((isset($this->foundClasses[$fileName])) && (!isset($this->loadedClasses[$this->foundClasses[$fileName]]))) { // File is found and not loaded so load it only once /* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - START' . PHP_EOL, __METHOD__, __LINE__, $fileName); - require($this->classes[$fileName]); + require($this->foundClasses[$fileName]); /* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - END' . PHP_EOL, __METHOD__, __LINE__, $fileName); // Count this loaded class/interface/exception $this->total++; // Mark this class as loaded for other purposes than loading it. - array_push($this->loadedClasses, $this->classes[$fileName]); + $this->loadedClasses[$this->foundClasses[$fileName]] = TRUE; // Remove it from classes list so it won't be found twice. /* NOISY-DEBUG: */ printf('[%s:%d] UNSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); - unset($this->classes[$fileName]); + unset($this->foundClasses[$fileName]); // Developer mode excludes caching (better debugging) if (!defined('DEVELOPER')) { @@ -465,15 +465,17 @@ class ClassLoader { */ private function includeExtraConfigs () { // Run through all class names (should not be much) - foreach ($this->classes as $fileName => $fqfn) { + foreach ($this->foundClasses as $fileName => $fqfn) { // Is this a config? if (substr($fileName, 0, strlen($this->prefix)) == $this->prefix) { // Then include it + /* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - START' . PHP_EOL, __METHOD__, __LINE__, $fileName); require($fqfn); + /* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - END' . PHP_EOL, __METHOD__, __LINE__, $fileName); // Remove it from the list /* NOISY-DEBUG: */ printf('[%s:%d] UNSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); - unset($this->classes[$fileName]); + unset($this->foundClasses[$fileName]); } // END - if } // END - foreach } -- 2.39.5