// Import framework stuff
use CoreFramework\Configuration\FrameworkConfiguration;
+use CoreFramework\Generic\EmptyVariableException;
+use CoreFramework\Loader\NoClassException;
/**
* An general object factory
}
// Create method name
- $methodName = sprintf('create%s', $className);
+ $methodName = sprintf('create%s', self::stripNamespaceFromClassName($className));
// Run the user function
$objectInstance = call_user_func_array(array($className, $methodName), $args);
return $objectInstance;
}
+ /**
+ * Strips of namespace from given class name. An exception is thrown when
+ * there is no namespace found as this is the now the norm for any objects
+ * being created with this object factory.
+ *
+ * @param $fullClassName Class name with namespace
+ * @return $shortClassName Stripped class name (no namespace)
+ * @throws InvalidClassNameException 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);
+ } // END - if
+
+ // Get last element
+ $shortClassName = array_pop($classNameParts);
+
+ // Return it
+ return $shortClassName;
+ }
+
}