forked from wilminator/dokuwiki-plugin-twofactor
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSettings.php
120 lines (104 loc) · 2.83 KB
/
Settings.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
<?php
namespace dokuwiki\plugin\twofactor;
/**
* Encapsulate the attribute plugin for per user/provider storage
*
* @todo maybe do our own settings saving with backwards compatibility to attribute?
*/
class Settings
{
/** @var \helper_plugin_attribute */
protected $attribute;
/** @var string Identifier of the provider these settings are for */
protected $providerID;
/** @var string Login of the user these settings are for */
protected $user;
/**
* @param string $module Name of the provider
* @param string $user User login
*/
public function __construct($module, $user)
{
$this->attribute = plugin_load('helper', 'attribute');
if ($this->attribute === null) throw new \RuntimeException('attribute plugin not found');
$this->attribute->setSecure(false);
$this->providerID = $module;
$this->user = $user;
}
/**
* Return a list of users that have settings for the given module
*
* @param $module
* @return array|bool
*/
static public function findUsers($module)
{
/** @var \helper_plugin_attribute $attribute */
$attribute = plugin_load('helper', 'attribute');
if ($attribute === null) throw new \RuntimeException('attribute plugin not found');
return $attribute->enumerateUsers($module);
}
/**
* Get the user these settings are for
*
* @return string
*/
public function getUser()
{
return $this->user;
}
/**
* Check if a setting exists
*
* @param string $key Settings key
* @return bool
*/
public function has($key)
{
return $this->attribute->exists($this->providerID, $key, $this->user);
}
/**
* Get a stored setting
*
* @param string $key Settings key
* @param mixed $default Default to return when no setting available
* @return mixed
*/
public function get($key, $default = null)
{
$success = false;
$data = $this->attribute->get($this->providerID, $key, $success, $this->user);
if (!$success) return $default;
return $data;
}
/**
* Store a settings value
*
* @param string $key Settings key
* @param mixed $value Value to store
* @return bool
*/
public function set($key, $value)
{
return $this->attribute->set($this->providerID, $key, $value, $this->user);
}
/**
* Delete a settings value
*
* @param string $key Settings key
* @return bool
*/
public function delete($key)
{
return $this->attribute->del($this->providerID, $key, $this->user);
}
/**
* Remove all settings
*
* @return bool
*/
public function purge()
{
return $this->attribute->purge($this->providerID, $this->user);
}
}