Permalink
Browse files

Merge branch 'wip-MDL-36819-m24-rb' of git://github.com/samhemelryk/m…

…oodle
  • Loading branch information...
2 parents f725158 + 2b274ad commit 155bd5d54a03d14df1b8ea769ef91cf5f4ad3022 @stronk7 stronk7 committed Nov 26, 2012
@@ -339,6 +339,35 @@ 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.
*
* The cache data source interface can be implemented by any class within Moodle.
View
@@ -790,7 +790,7 @@ public static function get_edit_store_form($plugin, $store) {
// 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 @@ public static function get_store_configuration_from_data(stdClass $data) {
}
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();
}
@@ -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.
@@ -37,7 +37,7 @@
* @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
@@ -43,8 +43,7 @@
* @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
@@ -37,7 +37,7 @@
* @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

0 comments on commit 155bd5d

Please sign in to comment.