* the class was not found. No parameters for the object are currently
* supported.
*
- * @param $className Name of the class we shall construct
- * @return $objectInstance An instance of the requested object
+ * @param $className Name of the class we shall construct
+ * @param $args Arguments in an indexed array
+ * @return $objectInstance An instance of the requested object
* @throws ClassNotFoundException If the requested class was not found
* @throws EmptyVariableException If a variable is empty unexpectly
*/
- public final static function createObjectByName ($className) {
+ public final static function createObjectByName ($className, array $args=array()) {
// First get an instance of this factory
$factoryInstance = new ObjectFactory();
throw new ClassNotFoundException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND);
}
- // Then Prepare the eval() command
- $eval = sprintf("\$objectInstance = %s::create%s();",
+ // Then Prepare the call-back function
+ $callback = sprintf("%s::create%s",
$className,
$className
);
- // Run the command
- eval($eval);
+ // Run the user function
+ $objectInstance = call_user_func_array($callback, $args);
// Return the prepared instance
return $objectInstance;
/**
* Creates an object by it's configured name
*
- * @param $configEnttry Configuration entry to read
- * @return $objectInstance An instance of the requested object
+ * @param $configEnttry Configuration entry to read
+ * @param $args Arguments in an indexed array
+ * @return $objectInstance An instance of the requested object
*/
- public final static function createObjectByConfiguredName ($configEntry) {
+ public final static function createObjectByConfiguredName ($configEntry, array $args=array()) {
// Read the configuration entry
$className = FrameworkConfiguration::getInstance()->readConfig($configEntry);
// Send this to the other factory...
- $objectInstance = self::createObjectByName($className);
+ $objectInstance = self::createObjectByName($className, $args);
// Return the instance
return $objectInstance;