From 38be68ad326a362dd73d0da85993ab7f2de59154 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 14 Mar 2017 12:20:54 +0100 Subject: [PATCH] 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. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- framework/loader/class_ClassLoader.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 -- 2.39.5