From 3076ba22dd8346725b4e1ad757532c00df5b18d9 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Fri, 2 Jan 2015 17:19:13 -0500 Subject: Fix bugs, improve perfs and use SimpleLogger instead of Monolog --- app/Core/Cache.php | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ app/Core/FileCache.php | 41 ++++++++++++++++++++++++++++++++++ app/Core/Helper.php | 16 +++++++++++++ app/Core/MemoryCache.php | 32 ++++++++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 app/Core/Cache.php create mode 100644 app/Core/FileCache.php create mode 100644 app/Core/MemoryCache.php (limited to 'app/Core') diff --git a/app/Core/Cache.php b/app/Core/Cache.php new file mode 100644 index 00000000..670a76e0 --- /dev/null +++ b/app/Core/Cache.php @@ -0,0 +1,58 @@ +container = $container; + $this->init(); + } + + /** + * Proxy cache + * + * Note: Arguments must be scalar types + * + * @access public + * @param string $container Container name + * @param string $method Container method + * @return mixed + */ + public function proxy($container, $method) + { + $args = func_get_args(); + $key = 'proxy_'.implode('_', $args); + $result = $this->get($key); + + if ($result === null) { + $result = call_user_func_array(array($this->container[$container], $method), array_splice($args, 2)); + $this->set($key, $result); + } + + return $result; + } +} diff --git a/app/Core/FileCache.php b/app/Core/FileCache.php new file mode 100644 index 00000000..2037f271 --- /dev/null +++ b/app/Core/FileCache.php @@ -0,0 +1,41 @@ +container[$name]; } + /** + * Proxy cache helper for acl::isManagerActionAllowed() + * + * @access public + * @param integer $project_id + * @return boolean + */ + public function isManager($project_id) + { + if ($this->userSession->isAdmin()) { + return true; + } + + return $this->container['memoryCache']->proxy('acl', 'isManagerActionAllowed', $project_id); + } + /** * Return the user full name * diff --git a/app/Core/MemoryCache.php b/app/Core/MemoryCache.php new file mode 100644 index 00000000..f80a66ef --- /dev/null +++ b/app/Core/MemoryCache.php @@ -0,0 +1,32 @@ +storage[$key] = $value; + } + + public function get($key) + { + return isset($this->storage[$key]) ? $this->storage[$key] : null; + } + + public function flush() + { + $this->storage = array(); + } + + public function remove($key) + { + unset($this->storage[$key]); + } +} -- cgit v1.2.3