2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Redis Cache Store - Add instance form
20 * @package cachestore_redis
21 * @copyright 2013 Adam Durana
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->dirroot.'/cache/forms.php');
30 * Form for adding instance of Redis Cache Store.
32 * @copyright 2013 Adam Durana
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 class cachestore_redis_addinstance_form extends cachestore_addinstance_form {
37 * Builds the form for creating an instance.
39 protected function configuration_definition() {
42 $form->addElement('text', 'server', get_string('server', 'cachestore_redis'), array('size' => 24));
43 $form->setType('server', PARAM_TEXT);
44 $form->addHelpButton('server', 'server', 'cachestore_redis');
45 $form->addRule('server', get_string('required'), 'required');
47 $form->addElement('text', 'prefix', get_string('prefix', 'cachestore_redis'), array('size' => 16));
48 $form->setType('prefix', PARAM_TEXT); // We set to text but we have a rule to limit to alphanumext.
49 $form->addHelpButton('prefix', 'prefix', 'cachestore_redis');
50 $form->addRule('prefix', get_string('prefixinvalid', 'cachestore_redis'), 'regex', '#^[a-zA-Z0-9\-_]+$#');
52 $serializeroptions = cachestore_redis::config_get_serializer_options();
53 $form->addElement('select', 'serializer', get_string('useserializer', 'cachestore_redis'), $serializeroptions);
54 $form->addHelpButton('serializer', 'useserializer', 'cachestore_redis');
55 $form->setDefault('serializer', Redis::SERIALIZER_PHP);
56 $form->setType('serializer', PARAM_INT);