X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Floader%2Fclass_ClassLoader.php;h=134b8c10d4af9d7a533065d105da41c4f92c09c6;hb=12dbc1af8f0bc2981711b17c7c955f270c440b35;hp=79e9f05ce1d9086fd7b057cc37ea356f493646ef;hpb=389f3abad52f9cde3323db5d3d187562fe801a71;p=hub.git diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index 79e9f05ce..134b8c10d 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -4,9 +4,9 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.ship-simu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -102,6 +102,11 @@ class ClassLoader { */ private $classCacheFQFN = ""; + /** + * Counter for loaded include files + */ + private $total = 0; + /** * The *public* constructor * @@ -114,8 +119,8 @@ class ClassLoader { // Construct the FQFN for the cache if (!defined('DEVELOPER')) { - $this->listCacheFQFN = PATH . $this->cfgInstance->readConfig('local_db_path') . "list-" . $this->cfgInstance->readConfig('app_name') . ".cache"; - $this->classCacheFQFN = PATH . $this->cfgInstance->readConfig('local_db_path') . "class-" . $this->cfgInstance->readConfig('app_name') . ".cache"; + $this->listCacheFQFN = $this->cfgInstance->readConfig('local_db_path') . "list-" . $this->cfgInstance->readConfig('app_name') . ".cache"; + $this->classCacheFQFN = $this->cfgInstance->readConfig('local_db_path') . "class-" . $this->cfgInstance->readConfig('app_name') . ".cache"; } // END - if // Set suffix and prefix from configuration @@ -203,8 +208,8 @@ class ClassLoader { /** * Scans recursively a local path for class files which must have a prefix and a suffix as given by $this->suffix and $this->prefix * - * @param $basePath The relative base path to PATH constant for all classes - * @param $ignoreList An optional list (array or string) of directory names which shall be ignored + * @param $basePath The relative base path to 'base_path' constant for all classes + * @param $ignoreList An optional list (array or string) of directory names which shall be ignored * @return void */ public function loadClasses ($basePath, $ignoreList = array() ) { @@ -235,7 +240,7 @@ class ClassLoader { // If the basePath is false it is invalid if ($basePath2 === false) { - // TODO: Do not die here. + /* @todo: Do not die here. */ die("Cannot read {$basePath} !"); } else { // Set base path @@ -275,14 +280,18 @@ class ClassLoader { $this->prefixLen = strlen($this->prefix); // Set base directory - $basePath = sprintf("%sinc/config/", PATH); + $basePath = sprintf("%sinc/config/", $this->cfgInstance->readConfig('base_path')); // Load all classes from the config directory $this->loadClasses($basePath); + // Include these extra configs now + $this->includeExtraConfigs(); + // Set the prefix back $this->prefix = $oldPrefix; $this->prefixLen = strlen($this->prefix); + } /** @@ -300,18 +309,67 @@ class ClassLoader { // Now look it up in our index if (isset($this->classes[$fileName])) { // File is found so load it only once + //* DEBUG: */ echo "LOAD: ".$fileName." - Start
\n"; require($this->classes[$fileName]); + //* DEBUG: */ echo "LOAD: ".$fileName." - End
\n"; + + // Count this include + $this->total++; + + // Mark this class as loaded + $this->loadedClasses[] = $this->classes[$fileName]; // Developer mode excludes caching (better debugging) if (!defined('DEVELOPER')) { - // Mark this class as loaded - $this->loadedClasses[] = $this->classes[$fileName]; - // Reset cache $this->classesCached = false; } // END - if } // END - if } + + /** + * Includes all extra config files + * + * @return void + */ + private function includeExtraConfigs () { + // Run through all class names (should not be much) + foreach ($this->classes as $fileName => $fqfn) { + // Is this a config? + if (substr($fileName, 0, $this->prefixLen) == $this->prefix) { + // Then include it + require($fqfn); + + // Remove it from the list + unset($this->classes[$fileName]); + } // END - if + } // END - foreach + } + + /** + * Getter for total include counter + * + * @return $total Total loaded include files + */ + public final function getTotal () { + return $this->total; + } + + /** + * Getter for a printable list of included classes/interfaces/exceptions + * + * @param $includeList A printable include list + */ + public function getPrintableIncludeList () { + // Prepare the list + $includeList = ""; + foreach ($this->loadedClasses as $classFile) { + $includeList .= basename($classFile)."
\n"; + } // END - foreach + + // And return it + return $includeList; + } } // [EOF]