X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Ffactories%2Fobjects%2Fclass_ObjectFactory.php;fp=inc%2Fclasses%2Fmain%2Ffactories%2Fobjects%2Fclass_ObjectFactory.php;h=0000000000000000000000000000000000000000;hp=0848e79fabd832f0405555e47de65481b1629c57;hb=398f4a89ecb5f6ef538e143d5ea84b569fb9d287;hpb=df33e264f3246f80756d7e2da55d7f7c40f9088c diff --git a/inc/classes/main/factories/objects/class_ObjectFactory.php b/inc/classes/main/factories/objects/class_ObjectFactory.php deleted file mode 100644 index 0848e79..0000000 --- a/inc/classes/main/factories/objects/class_ObjectFactory.php +++ /dev/null @@ -1,111 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class ObjectFactory extends BaseFactory { - /** - * Total objects generated - */ - private static $total = 0; - - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates a new object given by the name or throws an exception if - * the class was not found. No parameters for the object are currently - * supported. - * - * @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, array $args=array()) { - // Is the class name valid and is the class there? - if (empty($className)) { - // First get an instance of this factory - $factoryInstance = new ObjectFactory(); - - // Throw an exception here - throw new EmptyVariableException(array($factoryInstance, 'className'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!class_exists($className)) { - // First get an instance of this factory - $factoryInstance = new ObjectFactory(); - - // Then throw an exception - throw new ClassNotFoundException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND); - } - - // Create method name - $methodName = sprintf("create%s", - $className - ); - - // Run the user function - $objectInstance = call_user_func_array(array($className, $methodName), $args); - - // Count generated objects up - self::$total++; - - // Return the prepared instance - return $objectInstance; - } - - /** - * Creates an object by it's configured name - * - * @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, array $args=array()) { - // Read the configuration entry - $className = FrameworkConfiguration::getInstance()->readConfig($configEntry); - - // Send this to the other factory... - $objectInstance = self::createObjectByName($className, $args); - - // Return the instance - return $objectInstance; - } - - /** - * Static getter for total object count - * - * @return $total Total amount of generated objects - */ - public final static function getTotal () { - return self::$total; - } -} - -// [EOF] -?>