renamed class property $classes to $foundClasses so it is clear that these
authorRoland Haeder <roland@mxchange.org>
Wed, 22 Feb 2017 22:39:56 +0000 (23:39 +0100)
committerRoland Haeder <roland@mxchange.org>
Tue, 28 Feb 2017 21:10:04 +0000 (22:10 +0100)
classes has only been found but not yet loaded (require()).

Signed-off-by: Roland H├Ąder <roland@mxchange.org>
inc/loader/class_ClassLoader.php

index ab7efc0..7dd6d63 100644 (file)
@@ -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
        }