X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Floader%2Fclass_ClassLoader.php;h=8886bd18e7ded2e7d19e8735303bbbcf73153ed2;hb=54ac435b892edabd140aadc9f5b07219b3d2344b;hp=8ce7f4fe7732bbae6608045a4ce689c6b0d6a98d;hpb=65f6c4366c9709c9c7c9070d903f1d948be0d5b0;p=core.git diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index 8ce7f4fe..8886bd18 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -14,7 +14,7 @@ use \RecursiveIteratorIterator; * This class loads class include files with a specific prefix and suffix * * @author Roland Haeder - * @version 0.0.0 + * @version 1.5.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org @@ -33,6 +33,10 @@ use \RecursiveIteratorIterator; * along with this program. If not, see . * * ---------------------------------- + * 1.5 + * - Namespace scheme Project\Package[\SubPackage...] is fully supported and + * throws an E_USER_WARNING if not present. The last part will be always the + * class' name. * 1.4 * - Some comments improved, other minor improvements * 1.3 @@ -275,7 +279,6 @@ class ClassLoader { */ public static function autoLoad ($className) { // Try to include this class - //* NOISY-DEBUG: */ printf('[%s:%d] className=%s' . PHP_EOL, __METHOD__, __LINE__, $className); self::getSelfInstance()->includeClass($className); } @@ -410,8 +413,20 @@ class ClassLoader { * @return void */ public function includeClass ($className) { + // The class name should contain at least 2 back-slashes, so split at them + $classNameParts = explode("\\", $className); + + // At least 3 parts should be there + if (count($classNameParts) < 3) { + // Namespace scheme is: Project\Package[\SubPackage...] + trigger_error(sprintf('Class name "%s" is not after naming-convention: Project\Package[\SubPackage...]', $className), E_USER_WARNING); + } // END - if + + // Get last element + $shortClassName = array_pop($classNameParts); + // Create a name with prefix and suffix - $fileName = $this->prefix . $className . $this->suffix; + $fileName = $this->prefix . $shortClassName . $this->suffix; // Now look it up in our index //* NOISY-DEBUG: */ printf('[%s:%d] ISSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName);