* @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));
*
* @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