]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/factories/objects/class_ObjectFactory.php
eval() commands replace by improved object factory, user login class stub added
[shipsimu.git] / inc / classes / main / factories / objects / class_ObjectFactory.php
index 19d0e3d8aa5049504700b312b76eecc5951cca85..8fe592bf86ea61e560a2ff7771201494e8ae405b 100644 (file)
@@ -43,12 +43,13 @@ class ObjectFactory extends BaseFactory {
         * 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();
 
@@ -61,14 +62,14 @@ class ObjectFactory extends BaseFactory {
                        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;
@@ -77,15 +78,16 @@ class ObjectFactory extends BaseFactory {
        /**
         * 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;