class_ObjectFactory.php

Go to the documentation of this file.
00001 <?php
00024 class ObjectFactory extends BaseFactory {
00028         private static $total = 0;
00029 
00035         protected function __construct () {
00036                 // Call parent constructor
00037                 parent::__construct(__CLASS__);
00038         }
00039 
00051         public final static function createObjectByName ($className, array $args=array()) {
00052                 // Is the class name valid and is the class there?
00053                 if (empty($className)) {
00054                         // First get an instance of this factory
00055                         $factoryInstance = new ObjectFactory();
00056 
00057                         // Throw an exception here
00058                         throw new EmptyVariableException(array($factoryInstance, 'className'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00059                 } elseif (!class_exists($className)) {
00060                         // First get an instance of this factory
00061                         $factoryInstance = new ObjectFactory();
00062 
00063                         // Then throw an exception
00064                         throw new ClassNotFoundException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND);
00065                 }
00066 
00067                 // Create method name
00068                 $methodName = sprintf("create%s",
00069                         $className
00070                 );
00071 
00072                 // Run the user function
00073                 $objectInstance = call_user_func_array(array($className, $methodName), $args);
00074 
00075                 // Count generated objects up
00076                 self::$total++;
00077 
00078                 // Return the prepared instance
00079                 return $objectInstance;
00080         }
00081 
00089         public final static function createObjectByConfiguredName ($configEntry, array $args=array()) {
00090                 // Read the configuration entry
00091                 $className = FrameworkConfiguration::getInstance()->readConfig($configEntry);
00092 
00093                 // Send this to the other factory...
00094                 $objectInstance = self::createObjectByName($className, $args);
00095 
00096                 // Return the instance
00097                 return $objectInstance;
00098         }
00099 
00105         public final static function getTotal () {
00106                 return self::$total;
00107         }
00108 }
00109 
00110 // [EOF]
00111 ?>

Generated on Mon Dec 8 01:06:45 2008 for Ship-Simulator by  doxygen 1.5.6