X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Floader%2Fclass_ClassLoader.php;h=af4d8d336c3ff9e89c61582814428ea57ec86505;hb=9781c5a0452bd661b7f2a5fb2da358d20ec6ab3b;hp=50f34f3772edeabfe11fe5d2da8996c9bff37b9f;hpb=2e80331da79b13c3094f9039d4c584e3e4b89894;p=core.git diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index 50f34f37..af4d8d33 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -2,11 +2,11 @@ /** * This class loads class include files with a specific prefix and suffix * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.shipsimu.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 @@ -98,6 +98,17 @@ class ClassLoader { */ private $total = 0; + /** + * Framework/application paths for classes, etc. + */ + private static $frameworkPaths = array( + 'exceptions', // Exceptions + 'interfaces', // Interfaces + 'main', // General main classes + 'middleware' // The middleware + ); + + /** * The protected constructor. Please use the factory method below, or use * getSelfInstance() for singleton @@ -157,6 +168,44 @@ class ClassLoader { return $loaderInstance; } + /** + * Scans for all framework classes, exceptions and interfaces. + * + * @return void + */ + public static function scanFrameworkClasses () { + // Cache loader instance + $loaderInstance = self::getSelfInstance(); + + // Load all classes + foreach (self::$frameworkPaths as $className) { + // Try to load the framework classes + $loaderInstance->scanClassPath('inc/classes/' . $className . '/'); + } // END - foreach + } + + /** + * Scans for application's classes, etc. + * + * @return void + */ + public static function scanApplicationClasses () { + // Get config instance + $cfg = FrameworkConfiguration::getSelfInstance(); + + // Load all classes for the application + foreach (self::$frameworkPaths as $class) { + // Create path name + $path = sprintf('%s/%s/%s', $cfg->getConfigEntry('application_path'), $cfg->getConfigEntry('app_name'), $class); + + // Is the path readable? + if (is_dir($path)) { + // Try to load the application classes + ClassLoader::getSelfInstance()->scanClassPath($path); + } // END - if + } // END - foreach + } + /** * Initializes our loader class * @@ -256,7 +305,6 @@ class ClassLoader { array_push($ignoreList, '.'); array_push($ignoreList, '..'); array_push($ignoreList, '.htaccess'); - array_push($ignoreList, '.svn'); // Keep it in class for later usage $this->ignoreList = $ignoreList; @@ -271,7 +319,7 @@ class ClassLoader { // If the basePath is FALSE it is invalid if ($basePath2 === FALSE) { /* @todo: Do not die here. */ - exit(__METHOD__ . ':Cannot read ' . $basePath . ' !'); + exit(__METHOD__ . ':Cannot read ' . $basePath . ' !' . PHP_EOL); } else { // Set base path $basePath = $basePath2; @@ -279,9 +327,9 @@ class ClassLoader { // Get a new iterator //* DEBUG: */ echo "Base path: {$basePath}
\n"; - $iterator = new RecursiveDirectoryIterator($basePath); - $recursive = new RecursiveIteratorIterator($iterator); - foreach ($recursive as $entry) { + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basePath)); + + foreach ($iterator as $entry) { // Get filename from iterator $fileName = $entry->getFileName();