// Get current entry
$currentEntry = $iteratorInstance->current();
- // Get filename from iterator
+ // Get filename from iterator which is the class' name (according naming-convention)
$fileName = $currentEntry->getFileName();
// Get the "FQFN" (path and file name)
*
* @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
+ * @throws InvalidArgumentException If strict-checking is enabled and class name is not following naming-convention
*/
private function loadClassFile ($className) {
// Trace message
use CoreFramework\Generic\EmptyVariableException;
use CoreFramework\Loader\NoClassException;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* An general object factory
*
* @return $objectInstance An instance of the requested object
* @throws NoClassException If the requested class was not found
* @throws EmptyVariableException If a variable is empty unexpectly
+ * @throws InvalidArgumentException If class name is not following naming-convention
*/
- public static final function createObjectByName ($className, array $args=array()) {
+ 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
} elseif (!class_exists($className)) {
// Then throw an exception
throw new NoClassException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND);
+ } elseif (count($classNameParts) < 3) {
+ // Namespaces are missing
+ throw new InvalidArgumentException(sprintf('Class name "%s" is not conform to naming-convention: Project\Package[\SubPackage...]\SomeFooBar', $className));
}
// Create method name
* @param $args Arguments in an indexed array
* @return $objectInstance An instance of the requested object
*/
- public static final function createObjectByConfiguredName ($configEntry, array $args=array()) {
+ public static final function createObjectByConfiguredName ($configEntry, array $args = array()) {
// Read the configuration entry
$className = FrameworkConfiguration::getSelfInstance()->getConfigEntry($configEntry);