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
00037 parent::__construct(__CLASS__);
00038 }
00039
00051 public final static function createObjectByName ($className, array $args=array()) {
00052
00053 if (empty($className)) {
00054
00055 $factoryInstance = new ObjectFactory();
00056
00057
00058 throw new EmptyVariableException(array($factoryInstance, 'className'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00059 } elseif (!class_exists($className)) {
00060
00061 $factoryInstance = new ObjectFactory();
00062
00063
00064 throw new ClassNotFoundException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND);
00065 }
00066
00067
00068 $methodName = sprintf("create%s",
00069 $className
00070 );
00071
00072
00073 $objectInstance = call_user_func_array(array($className, $methodName), $args);
00074
00075
00076 self::$total++;
00077
00078
00079 return $objectInstance;
00080 }
00081
00089 public final static function createObjectByConfiguredName ($configEntry, array $args=array()) {
00090
00091 $className = FrameworkConfiguration::getInstance()->readConfig($configEntry);
00092
00093
00094 $objectInstance = self::createObjectByName($className, $args);
00095
00096
00097 return $objectInstance;
00098 }
00099
00105 public final static function getTotal () {
00106 return self::$total;
00107 }
00108 }
00109
00110
00111 ?>