From c6a8b23efa864cc90a3528f02eccbd6a89931220 Mon Sep 17 00:00:00 2001 From: Joey Schulze Date: Sun, 9 Jul 2017 12:14:54 +0200 Subject: [PATCH] Introduce caching factory for objects --- class/factory.class.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 class/factory.class.php diff --git a/class/factory.class.php b/class/factory.class.php new file mode 100644 index 0000000..b2330e5 --- /dev/null +++ b/class/factory.class.php @@ -0,0 +1,36 @@ +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; + } +} -- 2.20.1