-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddinstanceform.php
124 lines (106 loc) · 5.93 KB
/
addinstanceform.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* RedisCluster Cache Store - Add instance form
*
* @package cachestore_rediscluster
* @copyright 2013 Adam Durana
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/cache/forms.php');
/**
* Form for adding instance of RedisCluster Cache Store.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cachestore_rediscluster_addinstance_form extends cachestore_addinstance_form {
/**
* Builds the form for creating an instance.
*/
protected function configuration_definition() {
$form = $this->_form;
if (!class_exists('RedisCluster')) {
return;
}
$form->addElement('text', 'server', get_string('server', 'cachestore_rediscluster'));
$form->addHelpButton('server', 'server', 'cachestore_rediscluster');
$form->addRule('server', get_string('required'), 'required');
$form->setType('server', PARAM_TEXT);
$form->addElement('text', 'serversecondary', get_string('serversecondary', 'cachestore_rediscluster'));
$form->addHelpButton('serversecondary', 'serversecondary', 'cachestore_rediscluster');
$form->addRule('serversecondary', get_string('required'), 'required');
$form->setType('serversecondary', PARAM_TEXT);
$form->addElement('text', 'prefix', get_string('prefix', 'cachestore_rediscluster'), ['size' => 16]);
$form->setType('prefix', PARAM_TEXT); // We set to text but we have a rule to limit to alphanumext.
$form->addHelpButton('prefix', 'prefix', 'cachestore_rediscluster');
$form->addRule('prefix', get_string('prefixinvalid', 'cachestore_rediscluster'), 'regex', '#^[a-zA-Z0-9\-_]+$#');
$opts = [
RedisCluster::FAILOVER_NONE => get_string('failovernone', 'cachestore_rediscluster'),
RedisCluster::FAILOVER_ERROR => get_string('failovererror', 'cachestore_rediscluster'),
RedisCluster::FAILOVER_DISTRIBUTE => get_string('failoverdistribute', 'cachestore_rediscluster'),
];
// Experimental setting, only add it if its available.
// https://github.com/phpredis/phpredis/pull/1896 .
if (defined('RedisCluster::FAILOVER_PREFERRED')) {
$opts[RedisCluster::FAILOVER_PREFERRED] = get_string('failoverpreferred', 'cachestore_rediscluster');
}
$form->addElement('select', 'failover', get_string('failover', 'cachestore_rediscluster'), $opts);
$form->addHelpButton('failover', 'failover', 'cachestore_rediscluster');
$form->setDefault('failover', RedisCluster::FAILOVER_NONE);
if (defined('RedisCluster::FAILOVER_PREFERRED')) {
$form->addElement('text', 'preferrednodes', get_string('preferrednodes', 'cachestore_rediscluster'));
$form->addHelpButton('preferrednodes', 'preferrednodes', 'cachestore_rediscluster');
$form->disabledIf('preferrednodes', 'failover', 'neq', RedisCluster::FAILOVER_PREFERRED);
$form->setType('preferrednodes', PARAM_TEXT);
$form->setDefault('preferrednodes', '');
}
$form->addElement('checkbox', 'persist', get_string('persist', 'cachestore_rediscluster'));
$form->addHelpButton('persist', 'persist', 'cachestore_rediscluster');
$form->setDefault('persist', 0);
$form->setType('persist', PARAM_BOOL);
$form->addElement('text', 'timeout', get_string('timeout', 'cachestore_rediscluster'));
$form->addHelpButton('timeout', 'timeout', 'cachestore_rediscluster');
$form->setType('timeout', PARAM_FLOAT);
$form->setDefault('timeout', '3.0');
$form->addElement('text', 'readtimeout', get_string('readtimeout', 'cachestore_rediscluster'));
$form->addHelpButton('readtimeout', 'readtimeout', 'cachestore_rediscluster');
$form->setType('readtimeout', PARAM_FLOAT);
$form->setDefault('readtimeout', '3.0');
$opts = [
Redis::SERIALIZER_PHP => get_string('serializerphp', 'cachestore_rediscluster'),
Redis::SERIALIZER_IGBINARY => get_string('serializerigbinary', 'cachestore_rediscluster'),
];
$form->addElement('select', 'serializer', get_string('serializer', 'cachestore_rediscluster'), $opts);
$form->addHelpButton('serializer', 'serializer', 'cachestore_rediscluster');
$form->setDefault('serializer', Redis::SERIALIZER_PHP);
$opts = [
Redis::COMPRESSION_NONE => get_string('compressionnone', 'cachestore_rediscluster'),
];
if (defined('Redis::COMPRESSION_LZ4')) {
$opts[Redis::COMPRESSION_LZ4] = get_string('compressionlz4', 'cachestore_rediscluster');
}
if (defined('Redis::COMPRESSION_LZF')) {
$opts[Redis::COMPRESSION_LZF] = get_string('compressionlzf', 'cachestore_rediscluster');
}
if (defined('Redis::COMPRESSION_ZSTD')) {
$opts[Redis::COMPRESSION_ZSTD] = get_string('compressionzstd', 'cachestore_rediscluster');
}
$form->addElement('select', 'compression', get_string('compression', 'cachestore_rediscluster'), $opts);
$form->addHelpButton('compression', 'compression', 'cachestore_rediscluster');
$form->setDefault('compression', Redis::COMPRESSION_NONE);
}
}