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.
*
// 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;
}
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();
}
* @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.
* @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
* @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
* @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