]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/factories/objects/class_ObjectFactory.php
Continued:
[core.git] / framework / main / classes / factories / objects / class_ObjectFactory.php
index f06a70a16b6a82a4ff32738853114b89ffdbb4b9..1066e47a0bccb298419b8b89edf648367b074a0a 100644 (file)
@@ -55,23 +55,26 @@ class ObjectFactory extends BaseFactory {
         * @throws      InvalidArgumentException        If className is empty or the name not following naming-convention
         */
        public static final function createObjectByName ($className, array $args = array()) {
-               // First get an instance of this factory
-               $factoryInstance = new ObjectFactory();
-
-               // Split class name on backslash to check naming-convention
-               $classNameParts = explode("\\", $className);
-
                // Is the class name valid and is the class there?
                if (empty($className)) {
                        // Throw an exception here
                        throw new InvalidArgumentException('Parameter "className" is empty');
                } elseif (!class_exists($className)) {
+                       // First get an instance of this factory
+                       $factoryInstance = new ObjectFactory();
+
                        // Then throw an exception
                        throw new NoClassException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND);
-               } elseif (count($classNameParts) < 3) {
+               }
+
+               // Split class name on backslash to check naming-convention
+               $classNameParts = explode("\\", $className);
+
+               // Okay, does it follow naming-convention?
+               if (count($classNameParts) < 4) {
                        // Namespaces are missing
                        throw new InvalidArgumentException(sprintf('Class name "%s" is not conform to naming-convention: Tld\Domain\Project\Package[\SubPackage...]\SomeFooBar', $className));
-               }
+               } // END - if
 
                // Create method name
                $methodName = sprintf('create%s', self::stripNamespaceFromClassName($className));
@@ -111,16 +114,16 @@ class ObjectFactory extends BaseFactory {
         *
         * @param       $fullClassName  Class name with namespace
         * @return      $shortClassName Stripped class name (no namespace)
-        * @throws      InvalidClassNameException       If the class name does not follow naming convention
+        * @throws      InvalidArgumentException        If the class name does not follow naming convention
         */
        private static function stripNamespaceFromClassName ($fullClassName) {
                // The class name should contain at least 2 back-slashes, so split at them
                $classNameParts = explode("\\", $fullClassName);
 
-               // At least 3 parts should be there
-               if (count($classNameParts) < 3) {
-                       // Namespace scheme is: Project\Package[\SubPackage...]
-                       throw new InvalidClassNameException($fullClassName, self::EXCEPTION_INVALID_CLASS_NAME);
+               // At least 4 parts should be there
+               if (count($classNameParts) < 4) {
+                       // Namespace scheme is: Tld\Project\Package[\SubPackage...]
+                       throw new InvalidArgumentException($fullClassName, self::EXCEPTION_INVALID_CLASS_NAME);
                } // END - if
 
                // Get last element