-
Notifications
You must be signed in to change notification settings - Fork 183
/
SpotSettings.php
executable file
·78 lines (64 loc) · 1.85 KB
/
SpotSettings.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
<?php
define('SPOTWEB_SETTINGS_VERSION', '0.01');
/*
* Classe om de server settings in op te slaan
*/
class SpotSettings {
private static $_instance = null;
private $_db;
private static $_settings;
/*
* Instantieert een nieuwe settings klasse
*/
public static function singleton(SpotDb $db, array $settings) {
if (self::$_instance === null) {
self::$_instance = new SpotSettings($db);
# haal alle settings op, en prepareer die
$dbSettings = $db->getAllSettings();
$tmpSettings = array();
foreach($dbSettings as $item) {
if ($item['serialized']) {
$item['value'] = unserialize($item['value']);
} # if
$tmpSettings[$item['name']] = $item['value'];
} # foreach
# en merge de settings met degene die we door krijgen
self::$_settings = array_merge($settings, $tmpSettings);
} # if
return self::$_instance;
} # singleton
/*
* Geeft de waarde van de setting terug
*/
function get($name) {
return self::$_settings[$name];
} # get
/*
* Set de waarde van de setting, maakt hem ook
* meteen persistent dus mee oppassen
*/
function set($name, $value) {
# Update onze eigen settings array zodat we meteen up-to-date zijn
self::$_settings[$name] = $value;
# maar zet het eventueel serialized in de database als dat nodig is
if ((is_array($value) || is_object($value))) {
$value = serialize($value);
$serialized = true;
} else {
$serialized = false;
} # if
$this->_db->updateSetting($name, $value, $serialized);
} # set
/*
* Bestaat de opgegeven setting ?
*/
function exists($name) {
return isset(self::$_settings[$name]);
} # isSet
/*
* Private constructor, moet altijd via singleton gaan
*/
private function __construct($db) {
$this->_db = $db;
} # ctor
} # class SpotSettings