From: Roland Häder Date: Tue, 14 Mar 2017 11:20:54 +0000 (+0100) Subject: strict naming-convention check can be disabled, but is not recommended in X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=38be68ad326a362dd73d0da85993ab7f2de59154;p=core.git strict naming-convention check can be disabled, but is not recommended in general use. For example for PhpUnit unit tests this must be disabled, else PHP_Invoker cannot be loaded. Signed-off-by: Roland Häder --- diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index 5ef930ce..6911f053 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -115,6 +115,11 @@ class ClassLoader { */ private $total = 0; + /** + * By default the class loader is strict with naming-convention check + */ + private static $strictNamingConventionCheck = TRUE; + /** * Framework/application paths for classes, etc. */ @@ -314,6 +319,16 @@ class ClassLoader { //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } + /** + * Enables or disables strict naming-convention tests on class loading + * + * @param $strictNamingConventionCheck Whether to strictly check naming-convention + * @return void + */ + public static function enableStrictNamingConventionCheck ($strictNamingConventionCheck = TRUE) { + self::$strictNamingConventionCheck = $strictNamingConventionCheck; + } + /** * Registeres given relative path where test classes reside. For regular * framework uses, they should not be loaded (and used). @@ -516,6 +531,7 @@ class ClassLoader { * * @param $className The class that shall be loaded * @return void + * @throws InvalidArgumentException If strict-checking is enabled and class name is not following naming convention */ private function loadClassFile ($className) { // Trace message @@ -525,7 +541,7 @@ class ClassLoader { $classNameParts = explode("\\", $className); // At least 3 parts should be there - if (count($classNameParts) < 3) { + if ((self::$strictNamingConventionCheck === TRUE) && (count($classNameParts) < 3)) { // Namespace scheme is: Project\Package[\SubPackage...] throw new InvalidArgumentException(sprintf('Class name "%s" is not conform to naming-convention: Project\Package[\SubPackage...]\SomeFooBar', $className)); } // END - if