--- /dev/null
+<?php
+
+final class Factory {
+ private static $objectStore = array();
+
+ public static function get()
+ {
+ if (!func_num_args())
+ throw new Exception('Factory::get called without class name');
+
+ $args = func_get_args();
+ $class = array_shift($args);
+
+ $obj = self::getInstance($class, $args);
+
+ if ($obj === false) {
+ $reflection = new ReflectionClass($class);
+ $obj = $reflection->newInstanceArgs($args);
+ self::$objectStore[$class][] = array('args' => $args, 'object' => $obj);
+ }
+
+ return $obj;
+ }
+
+ private static function getInstance($class, $args)
+ {
+ if (!array_key_exists($class, self::$objectStore)) return false;
+
+ foreach (self::$objectStore[$class] as $item) {
+ if ($item['args'] == $args)
+ return $item['object'];
+ }
+
+ return false;
+ }
+}