]> git.mxchange.org Git - core.git/commitdiff
strict naming-convention check can be disabled, but is not recommended in
authorRoland Häder <roland@mxchange.org>
Tue, 14 Mar 2017 11:20:54 +0000 (12:20 +0100)
committerRoland Häder <roland@mxchange.org>
Tue, 14 Mar 2017 11:20:54 +0000 (12:20 +0100)
general use. For example for PhpUnit unit tests this must be disabled, else
PHP_Invoker cannot be loaded.

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/loader/class_ClassLoader.php

index 5ef930ce25d6102f8baba52b90df27e6e76ca229..6911f053e24c24fb0c9a4762b0401277db1cec5e 100644 (file)
@@ -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