summaryrefslogtreecommitdiffstats
path: root/inc/property.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-05-21 18:41:25 +0200
committerSimon Rettberg2014-05-21 18:41:25 +0200
commit04123643da499bac9eed8e8d1198a4c69148075f (patch)
tree7da0dd36344624df67926b5f6312f11eca24e040 /inc/property.inc.php
parentJS Stuff for Taskmanager interaction (diff)
downloadslx-admin-04123643da499bac9eed8e8d1198a4c69148075f.tar.gz
slx-admin-04123643da499bac9eed8e8d1198a4c69148075f.tar.xz
slx-admin-04123643da499bac9eed8e8d1198a4c69148075f.zip
Server Setup page
Diffstat (limited to 'inc/property.inc.php')
-rw-r--r--inc/property.inc.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/inc/property.inc.php b/inc/property.inc.php
new file mode 100644
index 00000000..a1c252a5
--- /dev/null
+++ b/inc/property.inc.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * Get or set simple key-value-pairs, backed by the database
+ * to make them persistent.
+ */
+class Property
+{
+ private static $cache = false;
+
+ /**
+ * Retrieve value from property store.
+ *
+ * @param string $key key to retrieve the value of
+ * @param mixed $default value to return if $key does not exist in the property store
+ * @return mixed the value attached to $key, or $default if $key does not exist
+ */
+ private static function get($key, $default = false)
+ {
+ if (self::$cache === false) {
+ $res = Database::simpleQuery("SELECT name, value FROM property");
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ self::$cache[$row['name']] = $row['value'];
+ }
+ }
+ if (!isset(self::$cache[$key])) return $default;
+ return self::$cache[$key];
+ }
+
+ /**
+ * Set value in property store.
+ *
+ * @param string $key key of value to set
+ * @param type $value the value to store for $key
+ */
+ private static function set($key, $value)
+ {
+ Database::exec("INSERT INTO property (name, value) VALUES (:key, :value)"
+ . " ON DUPLICATE KEY UPDATE value = VALUES(value)", array(
+ 'key' => $key,
+ 'value' => $value
+ ));
+ if (self::$cache !== false) {
+ self::$cache[$key] = $value;
+ }
+ }
+
+ public static function getServerIp()
+ {
+ return self::get('server-ip', 'none');
+ }
+
+ public static function setServerIp($value)
+ {
+ self::set('server-ip', $value);
+ }
+
+} \ No newline at end of file