diff options
author | Igor Wiedler <igor@wiedler.ch> | 2010-11-03 18:35:31 +0100 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2011-01-09 23:49:35 +0100 |
commit | 9329b16ab13f3a4caf107df358c3c58bda2dcd8a (patch) | |
tree | 0b5faa7111c792565062c93b1c1a44eda50d4664 /phpBB/includes | |
parent | 36e95f939db9b88b8519d956120d161102184ccb (diff) | |
download | forums-9329b16ab13f3a4caf107df358c3c58bda2dcd8a.tar forums-9329b16ab13f3a4caf107df358c3c58bda2dcd8a.tar.gz forums-9329b16ab13f3a4caf107df358c3c58bda2dcd8a.tar.bz2 forums-9329b16ab13f3a4caf107df358c3c58bda2dcd8a.tar.xz forums-9329b16ab13f3a4caf107df358c3c58bda2dcd8a.zip |
[task/acm-refactor] Refactor the ACM classes to have a common interface.
They are now refered to as cache drivers rather than ACM classes. The
additional utility functions from the original cache class have been
moved to the cache_service. The class loader is now instantiated without
a cache instance and passed one as soon as it is constructed to allow
autoloading the cache classes.
PHPBB3-9983
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/cache/driver/apc.php (renamed from phpBB/includes/acm/acm_apc.php) | 8 | ||||
-rw-r--r-- | phpBB/includes/cache/driver/base.php | 24 | ||||
-rw-r--r-- | phpBB/includes/cache/driver/eaccelerator.php (renamed from phpBB/includes/acm/acm_eaccelerator.php) | 8 | ||||
-rw-r--r-- | phpBB/includes/cache/driver/file.php (renamed from phpBB/includes/acm/acm_file.php) | 6 | ||||
-rw-r--r-- | phpBB/includes/cache/driver/interface.php | 104 | ||||
-rw-r--r-- | phpBB/includes/cache/driver/memcache.php (renamed from phpBB/includes/acm/acm_memcache.php) | 12 | ||||
-rw-r--r-- | phpBB/includes/cache/driver/memory.php (renamed from phpBB/includes/acm/acm_memory.php) | 4 | ||||
-rw-r--r-- | phpBB/includes/cache/driver/null.php (renamed from phpBB/includes/acm/acm_null.php) | 4 | ||||
-rw-r--r-- | phpBB/includes/cache/driver/xcache.php (renamed from phpBB/includes/acm/acm_xcache.php) | 14 | ||||
-rw-r--r-- | phpBB/includes/cache/factory.php | 52 | ||||
-rw-r--r-- | phpBB/includes/cache/service.php (renamed from phpBB/includes/cache.php) | 57 | ||||
-rw-r--r-- | phpBB/includes/class_loader.php | 21 |
12 files changed, 244 insertions, 70 deletions
diff --git a/phpBB/includes/acm/acm_apc.php b/phpBB/includes/cache/driver/apc.php index ab00b43e60..a97cbe4dd1 100644 --- a/phpBB/includes/acm/acm_apc.php +++ b/phpBB/includes/cache/driver/apc.php @@ -16,17 +16,11 @@ if (!defined('IN_PHPBB')) exit; } -// Include the abstract base -if (!class_exists('acm_memory')) -{ - require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx"); -} - /** * ACM for APC * @package acm */ -class acm extends acm_memory +class phpbb_cache_driver_apc extends phpbb_cache_driver_memory { var $extension = 'apc'; diff --git a/phpBB/includes/cache/driver/base.php b/phpBB/includes/cache/driver/base.php new file mode 100644 index 0000000000..a71eca45d7 --- /dev/null +++ b/phpBB/includes/cache/driver/base.php @@ -0,0 +1,24 @@ +<?php +/** +* +* @package acm +* @version $Id$ +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* @package acm +*/ +abstract class phpbb_cache_driver_base implements phpbb_cache_driver_interface +{ +} diff --git a/phpBB/includes/acm/acm_eaccelerator.php b/phpBB/includes/cache/driver/eaccelerator.php index 7ae1557beb..b2dd37dbb5 100644 --- a/phpBB/includes/acm/acm_eaccelerator.php +++ b/phpBB/includes/cache/driver/eaccelerator.php @@ -16,18 +16,12 @@ if (!defined('IN_PHPBB')) exit; } -// Include the abstract base -if (!class_exists('acm_memory')) -{ - require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx"); -} - /** * ACM for eAccelerator * @package acm * @todo Missing locks from destroy() talk with David */ -class acm extends acm_memory +class phpbb_cache_driver_eaccelerator extends phpbb_cache_driver_memory { var $extension = 'eaccelerator'; var $function = 'eaccelerator_get'; diff --git a/phpBB/includes/acm/acm_file.php b/phpBB/includes/cache/driver/file.php index 0e60cd6940..e26fecf534 100644 --- a/phpBB/includes/acm/acm_file.php +++ b/phpBB/includes/cache/driver/file.php @@ -20,7 +20,7 @@ if (!defined('IN_PHPBB')) * ACM File Based Caching * @package acm */ -class acm +class phpbb_cache_driver_file extends phpbb_cache_driver_base { var $vars = array(); var $var_expires = array(); @@ -33,10 +33,10 @@ class acm /** * Set cache path */ - function acm() + function __construct($cache_dir = null) { global $phpbb_root_path; - $this->cache_dir = $phpbb_root_path . 'cache/'; + $this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_root_path . 'cache/'; } /** diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php new file mode 100644 index 0000000000..91d364abf6 --- /dev/null +++ b/phpBB/includes/cache/driver/interface.php @@ -0,0 +1,104 @@ +<?php +/** +* +* @package acm +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* An interface that all cache drivers must implement +* +* @package acm +*/ +interface phpbb_cache_driver_interface +{ + /** + * Load global cache + */ + public function load(); + + /** + * Unload cache object + */ + public function unload(); + + /** + * Save modified objects + */ + public function save(); + + /** + * Tidy cache + */ + public function tidy(); + + /** + * Get saved cache object + */ + public function get($var_name); + + /** + * Put data into cache + */ + public function put($var_name, $var, $ttl = 0); + + /** + * Purge cache data + */ + public function purge(); + + /** + * Destroy cache data + */ + public function destroy($var_name, $table = ''); + + /** + * Check if a given cache entry exist + */ + public function _exists($var_name); + + /** + * Load cached sql query + */ + public function sql_load($query); + + /** + * Save sql query + */ + public function sql_save($query, &$query_result, $ttl); + + /** + * Ceck if a given sql query exist in cache + */ + public function sql_exists($query_id); + + /** + * Fetch row from cache (database) + */ + public function sql_fetchrow($query_id); + + /** + * Fetch a field from the current row of a cached database result (database) + */ + public function sql_fetchfield($query_id, $field); + + /** + * Seek a specific row in an a cached database result (database) + */ + public function sql_rowseek($rownum, $query_id); + + /** + * Free memory used for a cached database result (database) + */ + public function sql_freeresult($query_id); +} diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/cache/driver/memcache.php index 527db71f80..46ba51049f 100644 --- a/phpBB/includes/acm/acm_memcache.php +++ b/phpBB/includes/cache/driver/memcache.php @@ -16,12 +16,6 @@ if (!defined('IN_PHPBB')) exit; } -// Include the abstract base -if (!class_exists('acm_memory')) -{ - require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx"); -} - if (!defined('PHPBB_ACM_MEMCACHE_PORT')) { define('PHPBB_ACM_MEMCACHE_PORT', 11211); @@ -47,17 +41,17 @@ if (!defined('PHPBB_ACM_MEMCACHE')) * ACM for Memcached * @package acm */ -class acm extends acm_memory +class phpbb_cache_driver_memcache extends phpbb_cache_driver_memory { var $extension = 'memcache'; var $memcache; var $flags = 0; - function acm() + function __construct() { // Call the parent constructor - parent::acm_memory(); + parent::__construct(); $this->memcache = new Memcache; foreach(explode(',', PHPBB_ACM_MEMCACHE) as $u) diff --git a/phpBB/includes/acm/acm_memory.php b/phpBB/includes/cache/driver/memory.php index d248487846..633a0fe699 100644 --- a/phpBB/includes/acm/acm_memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -20,7 +20,7 @@ if (!defined('IN_PHPBB')) * ACM Abstract Memory Class * @package acm */ -class acm_memory +class phpbb_cache_driver_memory extends phpbb_cache_driver_base { var $key_prefix; @@ -34,7 +34,7 @@ class acm_memory /** * Set cache path */ - function acm_memory() + function __construct() { global $phpbb_root_path, $dbname, $table_prefix; diff --git a/phpBB/includes/acm/acm_null.php b/phpBB/includes/cache/driver/null.php index 79f2b59c0f..0a520b572e 100644 --- a/phpBB/includes/acm/acm_null.php +++ b/phpBB/includes/cache/driver/null.php @@ -20,12 +20,12 @@ if (!defined('IN_PHPBB')) * ACM Null Caching * @package acm */ -class acm +class phpbb_cache_driver_null extends phpbb_cache_driver_base { /** * Set cache path */ - function acm() + function __construct() { } diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/cache/driver/xcache.php index 8be0ad0c48..9363ff501d 100644 --- a/phpBB/includes/acm/acm_xcache.php +++ b/phpBB/includes/cache/driver/xcache.php @@ -16,12 +16,6 @@ if (!defined('IN_PHPBB')) exit; } -// Include the abstract base -if (!class_exists('acm_memory')) -{ - require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx"); -} - /** * ACM for XCache * @package acm @@ -31,13 +25,13 @@ if (!class_exists('acm_memory')) * - xcache.admin.enable_auth = off (or xcache.admin.user and xcache.admin.password set) * */ -class acm extends acm_memory +class phpbb_cache_driver_xcache extends phpbb_cache_driver_memory { var $extension = 'XCache'; - function acm() + function __construct() { - parent::acm_memory(); + parent::__construct(); if (!function_exists('ini_get') || (int) ini_get('xcache.var_size') <= 0) { @@ -111,7 +105,7 @@ class acm extends acm_memory * @access protected * @param string $var Cache key * @return bool True if it exists, otherwise false - */ + */ function _isset($var) { return xcache_isset($this->key_prefix . $var); diff --git a/phpBB/includes/cache/factory.php b/phpBB/includes/cache/factory.php new file mode 100644 index 0000000000..cc88780bf2 --- /dev/null +++ b/phpBB/includes/cache/factory.php @@ -0,0 +1,52 @@ +<?php +/** +* +* @package acm +* @version $Id$ +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* @package acm +*/ +class phpbb_cache_factory +{ + private $acm_type; + + public function __construct($acm_type) + { + $this->acm_type = $acm_type; + } + + public function get_acm() + { + $class_name = 'phpbb_cache_driver_' . $this->acm_type; + return new $class_name(); + } + + public function get_service() + { + $acm = $this->get_acm(); + $service = new phpbb_cache_service($acm); + return $service; + } + + /** + * for convenience to allow: + * $cache = phpbb_cache_factory::create('file')->get_service(); + */ + public static function create($acm_type) + { + return new self($acm_type); + } +} diff --git a/phpBB/includes/cache.php b/phpBB/includes/cache/service.php index 49b690f1a4..424606bfc8 100644 --- a/phpBB/includes/cache.php +++ b/phpBB/includes/cache/service.php @@ -17,11 +17,28 @@ if (!defined('IN_PHPBB')) } /** -* Class for grabbing/handling cached entries, extends acm_file or acm_db depending on the setup +* Class for grabbing/handling cached entries * @package acm */ -class cache extends acm +class phpbb_cache_service { + private $acm; + + public function __construct(phpbb_cache_driver_interface $acm = null) + { + $this->set_acm($acm); + } + + public function set_acm(phpbb_cache_driver_interface $acm) + { + $this->acm = $acm; + } + + public function __call($method, $arguments) + { + return call_user_func_array(array($this->acm, $method), $arguments); + } + /** * Get config values */ @@ -29,7 +46,7 @@ class cache extends acm { global $db; - if (($config = $this->get('config')) !== false) + if (($config = $this->acm->get('config')) !== false) { $sql = 'SELECT config_name, config_value FROM ' . CONFIG_TABLE . ' @@ -61,7 +78,7 @@ class cache extends acm } $db->sql_freeresult($result); - $this->put('config', $cached_config); + $this->acm->put('config', $cached_config); } return $config; @@ -75,7 +92,7 @@ class cache extends acm { global $db; - if (($censors = $this->get('_word_censors')) === false) + if (($censors = $this->acm->get('_word_censors')) === false) { $sql = 'SELECT word, replacement FROM ' . WORDS_TABLE; @@ -89,7 +106,7 @@ class cache extends acm } $db->sql_freeresult($result); - $this->put('_word_censors', $censors); + $this->acm->put('_word_censors', $censors); } return $censors; @@ -100,7 +117,7 @@ class cache extends acm */ function obtain_icons() { - if (($icons = $this->get('_icons')) === false) + if (($icons = $this->acm->get('_icons')) === false) { global $db; @@ -120,7 +137,7 @@ class cache extends acm } $db->sql_freeresult($result); - $this->put('_icons', $icons); + $this->acm->put('_icons', $icons); } return $icons; @@ -131,7 +148,7 @@ class cache extends acm */ function obtain_ranks() { - if (($ranks = $this->get('_ranks')) === false) + if (($ranks = $this->acm->get('_ranks')) === false) { global $db; @@ -161,7 +178,7 @@ class cache extends acm } $db->sql_freeresult($result); - $this->put('_ranks', $ranks); + $this->acm->put('_ranks', $ranks); } return $ranks; @@ -176,7 +193,7 @@ class cache extends acm */ function obtain_attach_extensions($forum_id) { - if (($extensions = $this->get('_extensions')) === false) + if (($extensions = $this->acm->get('_extensions')) === false) { global $db; @@ -220,7 +237,7 @@ class cache extends acm } $db->sql_freeresult($result); - $this->put('_extensions', $extensions); + $this->acm->put('_extensions', $extensions); } // Forum post @@ -281,7 +298,7 @@ class cache extends acm */ function obtain_bots() { - if (($bots = $this->get('_bots')) === false) + if (($bots = $this->acm->get('_bots')) === false) { global $db; @@ -320,7 +337,7 @@ class cache extends acm } $db->sql_freeresult($result); - $this->put('_bots', $bots); + $this->acm->put('_bots', $bots); } return $bots; @@ -341,7 +358,7 @@ class cache extends acm foreach ($parsed_items as $key => $parsed_array) { - $parsed_array = $this->get('_cfg_' . $key . '_' . $theme[$key . '_path']); + $parsed_array = $this->acm->get('_cfg_' . $key . '_' . $theme[$key . '_path']); if ($parsed_array === false) { @@ -367,7 +384,7 @@ class cache extends acm $parsed_array = parse_cfg_file($filename); $parsed_array['filetime'] = @filemtime($filename); - $this->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array); + $this->acm->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array); } $parsed_items[$key] = $parsed_array; } @@ -380,7 +397,7 @@ class cache extends acm */ function obtain_disallowed_usernames() { - if (($usernames = $this->get('_disallowed_usernames')) === false) + if (($usernames = $this->acm->get('_disallowed_usernames')) === false) { global $db; @@ -395,7 +412,7 @@ class cache extends acm } $db->sql_freeresult($result); - $this->put('_disallowed_usernames', $usernames); + $this->acm->put('_disallowed_usernames', $usernames); } return $usernames; @@ -408,7 +425,7 @@ class cache extends acm { global $phpbb_root_path, $phpEx; - if (($hook_files = $this->get('_hooks')) === false) + if (($hook_files = $this->acm->get('_hooks')) === false) { $hook_files = array(); @@ -427,7 +444,7 @@ class cache extends acm closedir($dh); } - $this->put('_hooks', $hook_files); + $this->acm->put('_hooks', $hook_files); } return $hook_files; diff --git a/phpBB/includes/class_loader.php b/phpBB/includes/class_loader.php index 5df654799a..fa121341aa 100644 --- a/phpBB/includes/class_loader.php +++ b/phpBB/includes/class_loader.php @@ -33,7 +33,7 @@ class phpbb_class_loader { private $phpbb_root_path; private $php_ext; - private $cache; + private $acm; private $cached_paths = array(); /** @@ -42,13 +42,14 @@ class phpbb_class_loader * * @param string $phpbb_root_path phpBB's root directory containing includes/ * @param string $php_ext The file extension for PHP files + * @param phpbb_acm_interface $acm An implementation of the phpBB cache interface. */ - public function __construct($phpbb_root_path, $php_ext = '.php', $cache = null) + public function __construct($phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $acm = null) { $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; - $this->set_cache($cache); + $this->set_acm($acm); } /** @@ -56,13 +57,13 @@ class phpbb_class_loader * the class loader will resolve paths by checking for the existance of every * directory in the class name every time. * - * @param acm $cache An implementation of the phpBB cache interface. + * @param phpbb_acm_interface $acm An implementation of the phpBB cache interface. */ - public function set_cache($cache = null) + public function set_acm(phpbb_cache_driver_interface $acm = null) { - if ($cache) + if ($acm) { - $this->cached_paths = $cache->get('class_loader'); + $this->cached_paths = $acm->get('class_loader'); if ($this->cached_paths === false) { @@ -70,7 +71,7 @@ class phpbb_class_loader } } - $this->cache = $cache; + $this->acm = $acm; } /** @@ -133,10 +134,10 @@ class phpbb_class_loader return false; } - if ($this->cache) + if ($this->acm) { $this->cached_paths[$class] = $relative_path; - $this->cache->put('class_loader', $this->cached_paths); + $this->acm->put('class_loader', $this->cached_paths); } return $path_prefix . $relative_path . $this->php_ext; |