From 2b274ad00102140aa5a021160ea1ea9b919a11f2 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Mon, 26 Nov 2012 08:31:06 +1300 Subject: [PATCH] MDL-36819 cache: implemented cache_is_configurable interface --- cache/classes/interfaces.php | 29 +++++++++++++++++++++++++++++ cache/locallib.php | 7 +++---- cache/stores/file/lib.php | 2 +- cache/stores/memcache/lib.php | 2 +- cache/stores/memcached/lib.php | 3 +-- cache/stores/mongodb/lib.php | 2 +- 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/cache/classes/interfaces.php b/cache/classes/interfaces.php index 07abb209c97..d54834961d0 100644 --- a/cache/classes/interfaces.php +++ b/cache/classes/interfaces.php @@ -338,6 +338,35 @@ interface cache_is_key_aware { public function has_all(array $keys); } +/** + * Cache store feature: configurable. + * + * This feature should be implemented by all cache stores that are configurable when adding an instance. + * It requires the implementation of methods required to convert form data into the a configuration array for the + * store instance, and then the reverse converting configuration data into an array that can be used to set the + * data for the edit form. + * + * Can be implemented by classes already implementing cache_store. + */ +interface cache_is_configurable { + + /** + * Given the data from the add instance form this function creates a configuration array. + * + * @param stdClass $data + * @return array + */ + public static function config_get_configuration_array($data); + + /** + * Allows the cache store to set its data against the edit form before it is shown to the user. + * + * @param moodleform $editform + * @param array $config + */ + public static function config_set_edit_form_data(moodleform $editform, array $config); +} + /** * Cache Data Source. * diff --git a/cache/locallib.php b/cache/locallib.php index d2b8f27dfc9..2b8087c5489 100644 --- a/cache/locallib.php +++ b/cache/locallib.php @@ -790,7 +790,7 @@ abstract class cache_administration_helper extends cache_helper { // If it has a customised add instance form then it is going to want to. $storeclass = 'cachestore_'.$plugin; $storedata = $stores[$store]; - if (array_key_exists('configuration', $storedata) && method_exists($storeclass, 'config_set_edit_form_data')) { + if (array_key_exists('configuration', $storedata) && array_key_exists('cache_is_configurable', class_implements($storeclass))) { $storeclass::config_set_edit_form_data($editform, $storedata['configuration']); } return $editform; @@ -848,12 +848,11 @@ abstract class cache_administration_helper extends cache_helper { } require_once($file); $class = 'cachestore_'.$data->plugin; - $method = 'config_get_configuration_array'; if (!class_exists($class)) { throw new coding_exception('Invalid cache plugin provided.'); } - if (method_exists($class, $method)) { - return call_user_func(array($class, $method), $data); + if (array_key_exists('cache_is_configurable', class_implements($class))) { + return $class::config_get_configuration_array($data); } return array(); } diff --git a/cache/stores/file/lib.php b/cache/stores/file/lib.php index af0b096c2cf..1d9bb427603 100644 --- a/cache/stores/file/lib.php +++ b/cache/stores/file/lib.php @@ -37,7 +37,7 @@ * @copyright 2012 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cachestore_file extends cache_store implements cache_is_key_aware { +class cachestore_file extends cache_store implements cache_is_key_aware, cache_is_configurable { /** * The name of the store. diff --git a/cache/stores/memcache/lib.php b/cache/stores/memcache/lib.php index c1530e97d92..80c5a33c391 100644 --- a/cache/stores/memcache/lib.php +++ b/cache/stores/memcache/lib.php @@ -37,7 +37,7 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2012 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cachestore_memcache extends cache_store { +class cachestore_memcache extends cache_store implements cache_is_configurable { /** * The name of the store diff --git a/cache/stores/memcached/lib.php b/cache/stores/memcached/lib.php index 96c4978f471..44a11b9ca6b 100644 --- a/cache/stores/memcached/lib.php +++ b/cache/stores/memcached/lib.php @@ -43,8 +43,7 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2012 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cachestore_memcached extends cache_store { - +class cachestore_memcached extends cache_store implements cache_is_configurable { /** * The name of the store * @var store diff --git a/cache/stores/mongodb/lib.php b/cache/stores/mongodb/lib.php index 2253bc22577..4ee7752cd86 100644 --- a/cache/stores/mongodb/lib.php +++ b/cache/stores/mongodb/lib.php @@ -37,7 +37,7 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2012 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cachestore_mongodb extends cache_store { +class cachestore_mongodb extends cache_store implements cache_is_configurable { /** * The name of the store