Move status change to AJAX
[infodrom.org/service.infodrom.org] / class / factory.class.php
1 <?php
2
3 final class Factory {
4   private static $objectStore = array();
5
6   public static function get()
7   {
8     if (!func_num_args())
9       throw new Exception('Factory::get called without class name');
10
11     $args = func_get_args();
12     $class = array_shift($args);
13
14     $obj = self::getInstance($class, $args);
15
16     if ($obj === false) {
17       $reflection = new ReflectionClass($class);
18       $obj = $reflection->newInstanceArgs($args);
19       self::$objectStore[$class][] = array('args' => $args, 'object' => $obj);
20     }
21
22     return $obj;
23   }
24
25   private static function getInstance($class, $args)
26   {
27     if (!array_key_exists($class, self::$objectStore)) return false;
28
29     foreach (self::$objectStore[$class] as $item) {
30       if ($item['args'] == $args)
31         return $item['object'];
32     }
33
34     return false;
35   }
36 }