/
PluginConfig.php
126 lines (115 loc) · 2.8 KB
/
PluginConfig.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
125
126
<?php
namespace XH;
use ArrayAccess;
/**
* Abstraction over the plugin (language) configuration.
*
* Instead of plain arrays, `$plugin_cf` and `$plugin_tx` are objects, which
* allow for lazy loading of the configuration and language files, respectively.
*
* @author The CMSimple_XH developers <devs@cmsimple-xh.org>
* @copyright 2017-2021 The CMSimple_XH developers <http://cmsimple-xh.org/?The_Team>
* @copyright GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.en.html>
* @since 1.7.0
*/
class PluginConfig implements ArrayAccess
{
/**
* Whether this is a language configuration.
*
* @var bool
*/
private $language;
/**
* The loaded plugin configurations.
*
* @var array
*/
private $configs = array();
/**
* Initializes a new instance.
*
* @param bool $language Whether this is a language configuration.
*/
public function __construct($language = false)
{
$this->language = $language;
}
/**
* Returns whether an offset exists.
*
* @param mixed $offset An offset.
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
if (!isset($this->configs[$offset])) {
$this->loadConfig($offset);
}
return isset($this->configs[$offset]);
}
/**
* Returns the value at an offset.
*
* @param mixed $offset An offset.
*
* @return array
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
if (!isset($this->configs[$offset])) {
$this->loadConfig($offset);
}
return $this->configs[$offset];
}
/**
* Sets the value at an offset.
*
* @param mixed $offset An offset.
* @param mixed $value A value.
*
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (!isset($this->configs[$offset])) {
$this->loadConfig($offset);
}
$this->configs[$offset] = $value;
}
/**
* Unsets an offset.
*
* @param mixed $offset An offset.
*
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
if (!isset($this->configs[$offset])) {
$this->loadConfig($offset);
}
unset($this->configs[$offset]);
}
/**
* Loads the configuration.
*
* @param string $pluginname A plugin name.
*
* @return void
*/
private function loadConfig($pluginname)
{
global $pth;
pluginFiles($pluginname);
if ($this->language) {
XH_createLanguageFile($pth['file']['plugin_language']);
}
$this->configs += XH_readConfiguration(true, $this->language);
}
}