ModuleSettings.php
1.21 KB
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
<?php
namespace YahnisElsts\AdminMenuEditor\Customizable\Storage;
//TODO: A module could have a method that sets up settings.
class ModuleSettings extends AbstractSettingsDictionary {
protected $settingCreationCallback;
public function __construct(
$optionName,
$scope = ScopedOptionStorage::GLOBAL_SCOPE,
$defaults = array(),
$settingCreationCallback = null,
$jsonSerializationEnabled = false,
$lastModifiedTimeEnabled = false
) {
$store = new ScopedOptionStorage($optionName, $scope);
$store->setJsonSerialization($jsonSerializationEnabled);
$this->defaults = $defaults;
$this->settingCreationCallback = $settingCreationCallback;
parent::__construct($store, $optionName . '--', $lastModifiedTimeEnabled);
}
protected function createDefaults() {
return $this->defaults;
}
protected function createSettings() {
if ( $this->settingCreationCallback !== null ) {
$settings = call_user_func($this->settingCreationCallback, $this);
//Index by ID.
$results = array();
foreach ($settings as $setting) {
$results[$setting->getId()] = $setting;
}
return $results;
}
return array();
}
/**
* @return StorageInterface
*/
public function getStore() {
return $this->store;
}
}