aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2012-05-20 12:55:27 +0200
committerKevin Chabowski <kevin@kch42.de>2012-05-20 12:55:27 +0200
commit1bfb9653d6e9139445ca9cde5808228c3b16399e (patch)
tree761b4d4e8734e090cd421ed24d6b4afffe821de7 /ratatoeskr/sys
parent160230943592591fe105efb85255284f6ff48a97 (diff)
downloadratatoeskr-cms-1bfb9653d6e9139445ca9cde5808228c3b16399e.tar.gz
ratatoeskr-cms-1bfb9653d6e9139445ca9cde5808228c3b16399e.tar.bz2
ratatoeskr-cms-1bfb9653d6e9139445ca9cde5808228c3b16399e.zip
Added silent mode to abstract KVStorage class.
Activated silent mode will return NULL instead of throwing an DoesNotExistError Exception, if a key does not exist.
Diffstat (limited to 'ratatoeskr/sys')
-rw-r--r--ratatoeskr/sys/models.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php
index bc48908..9f3a96a 100644
--- a/ratatoeskr/sys/models.php
+++ b/ratatoeskr/sys/models.php
@@ -88,14 +88,23 @@ abstract class BySQLRowEnabled
}
}
+/*
+ * Class: KVStorage
+ * An abstract class for a KVStorage.
+ *
+ * See also:
+ * <PluginKVStorage>, <ArticleExtradata>
+ */
abstract class KVStorage implements Countable, ArrayAccess, Iterator
{
private $keybuffer;
private $counter;
private $prepared_queries;
+ private $silent_mode;
final protected function init($sqltable, $common_fields)
{
+ $this->silent_mode = False;
$this->keybuffer = array();
$selector = "WHERE " . (empty($common_fields) ? 1 : implode(" AND ", array_map(function($x) { return qdb_fmt("`{$x[0]}` = {$x[1]}", $x[2]); }, $common_fields)));
@@ -117,6 +126,17 @@ abstract class KVStorage implements Countable, ArrayAccess, Iterator
$this->counter = 0;
}
+ /*
+ * Functions: Silent mode
+ * If the silent mode is enabled, the KVStorage behaves even more like a PHP array, i.e. it just returns NULL,
+ * if a unknown key was requested and does not throw an DoesNotExistError Exception.
+ *
+ * enable_silent_mode - Enable the silent mode.
+ * disable_silent_mode - Disable the silent mode (default).
+ */
+ final public function enable_silent_mode() { $this->silent_mode = True; }
+ final public function disable_silent_mode() { $this->silent_mode = False; }
+
/* Countable interface implementation */
final public function count() { return count($this->keybuffer); }
@@ -130,6 +150,8 @@ abstract class KVStorage implements Countable, ArrayAccess, Iterator
$sqlrow = mysql_fetch_assoc($result);
return unserialize(base64_decode($sqlrow["value"]));
}
+ elseif($this->silent_mode)
+ return NULL;
else
throw new DoesNotExistError();
}
@@ -844,6 +866,8 @@ $ratatoeskr_settings = Settings::get_instance();
* A Key-Value-Storage for Plugins
* Can be accessed like an array.
* Keys are strings and Values can be everything serialize() can process.
+ *
+ * Extends the abstract <KVStorage> class.
*/
class PluginKVStorage extends KVStorage
{
@@ -2634,6 +2658,8 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting");
* A Key-Value-Storage assigned to Articles for plugins to store additional data.
* Can be accessed like an array.
* Keys are strings and Values can be everything serialize() can process.
+ *
+ * Extends the abstract <KVStorage> class.
*/
class ArticleExtradata extends KVStorage
{