-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtpasswd-options-generic.php
48 lines (39 loc) · 1.29 KB
/
htpasswd-options-generic.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
<?php
class HtpasswdGenericOptions
{
public static $name = 'cnj_htpasswd_generic_options';
public static $resource_paths = 'resource_paths';
private $options;
private function __construct($options) {
$this->options = $options;
}
public static function load() {
return new HtpasswdGenericOptions(get_option(HtpasswdGenericOptions::$name));
}
public static function from($option_map) {
return new HtpasswdGenericOptions($option_map);
}
public function getPaths() {
return $this->options[HtpasswdGenericOptions::$resource_paths];
}
public function hasPaths() {
$val = $this->options[HtpasswdGenericOptions::$resource_paths];
return !empty($val);
}
public function getPathsAsArray() {
$val = $this->options[HtpasswdGenericOptions::$resource_paths];
if (!empty($val)) {
return $this->sanitize(explode(",", $val));
} else {
return array();
}
}
private function sanitize($from_array) {
$to_array = array();
foreach ($from_array as $v) {
$val = trim($v);
$to_array[] = substr($val, 0, 1) === '/' ? substr($val, 1, strlen($val)) : $val;
}
return $to_array;
}
}