Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-36819 cache: implemented cache_is_configurable interface

  • Loading branch information...
commit 2b274ad00102140aa5a021160ea1ea9b919a11f2 1 parent 75cde6b
Sam Hemelryk samhemelryk authored
29 cache/classes/interfaces.php
@@ -339,6 +339,35 @@ public function has_all(array $keys);
339 339 }
340 340
341 341 /**
  342 + * Cache store feature: configurable.
  343 + *
  344 + * This feature should be implemented by all cache stores that are configurable when adding an instance.
  345 + * It requires the implementation of methods required to convert form data into the a configuration array for the
  346 + * store instance, and then the reverse converting configuration data into an array that can be used to set the
  347 + * data for the edit form.
  348 + *
  349 + * Can be implemented by classes already implementing cache_store.
  350 + */
  351 +interface cache_is_configurable {
  352 +
  353 + /**
  354 + * Given the data from the add instance form this function creates a configuration array.
  355 + *
  356 + * @param stdClass $data
  357 + * @return array
  358 + */
  359 + public static function config_get_configuration_array($data);
  360 +
  361 + /**
  362 + * Allows the cache store to set its data against the edit form before it is shown to the user.
  363 + *
  364 + * @param moodleform $editform
  365 + * @param array $config
  366 + */
  367 + public static function config_set_edit_form_data(moodleform $editform, array $config);
  368 +}
  369 +
  370 +/**
342 371 * Cache Data Source.
343 372 *
344 373 * The cache data source interface can be implemented by any class within Moodle.
7 cache/locallib.php
@@ -790,7 +790,7 @@ public static function get_edit_store_form($plugin, $store) {
790 790 // If it has a customised add instance form then it is going to want to.
791 791 $storeclass = 'cachestore_'.$plugin;
792 792 $storedata = $stores[$store];
793   - if (array_key_exists('configuration', $storedata) && method_exists($storeclass, 'config_set_edit_form_data')) {
  793 + if (array_key_exists('configuration', $storedata) && array_key_exists('cache_is_configurable', class_implements($storeclass))) {
794 794 $storeclass::config_set_edit_form_data($editform, $storedata['configuration']);
795 795 }
796 796 return $editform;
@@ -848,12 +848,11 @@ public static function get_store_configuration_from_data(stdClass $data) {
848 848 }
849 849 require_once($file);
850 850 $class = 'cachestore_'.$data->plugin;
851   - $method = 'config_get_configuration_array';
852 851 if (!class_exists($class)) {
853 852 throw new coding_exception('Invalid cache plugin provided.');
854 853 }
855   - if (method_exists($class, $method)) {
856   - return call_user_func(array($class, $method), $data);
  854 + if (array_key_exists('cache_is_configurable', class_implements($class))) {
  855 + return $class::config_get_configuration_array($data);
857 856 }
858 857 return array();
859 858 }
2  cache/stores/file/lib.php
@@ -37,7 +37,7 @@
37 37 * @copyright 2012 Sam Hemelryk
38 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 39 */
40   -class cachestore_file extends cache_store implements cache_is_key_aware {
  40 +class cachestore_file extends cache_store implements cache_is_key_aware, cache_is_configurable {
41 41
42 42 /**
43 43 * The name of the store.
2  cache/stores/memcache/lib.php
@@ -37,7 +37,7 @@
37 37 * @copyright 2012 Sam Hemelryk
38 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 39 */
40   -class cachestore_memcache extends cache_store {
  40 +class cachestore_memcache extends cache_store implements cache_is_configurable {
41 41
42 42 /**
43 43 * The name of the store
3  cache/stores/memcached/lib.php
@@ -43,8 +43,7 @@
43 43 * @copyright 2012 Sam Hemelryk
44 44 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45 45 */
46   -class cachestore_memcached extends cache_store {
47   -
  46 +class cachestore_memcached extends cache_store implements cache_is_configurable {
48 47 /**
49 48 * The name of the store
50 49 * @var store
2  cache/stores/mongodb/lib.php
@@ -37,7 +37,7 @@
37 37 * @copyright 2012 Sam Hemelryk
38 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 39 */
40   -class cachestore_mongodb extends cache_store {
  40 +class cachestore_mongodb extends cache_store implements cache_is_configurable {
41 41
42 42 /**
43 43 * The name of the store

0 comments on commit 2b274ad

Please sign in to comment.
Something went wrong with that request. Please try again.