Created
March 3, 2012 21:16
-
-
Save heyrocker/1968307 to your computer and use it in GitHub Desktop.
code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface KeyValueInterface { | |
/** | |
* Constructs a new key/value collection. | |
* | |
* @param $collection | |
* The collection for which the object is created. | |
*/ | |
function __construct($collection); | |
/** | |
* Returns data from the key/value store. | |
* | |
* @param $key | |
* The key of the data to retrieve. | |
* | |
* @return | |
* The value or FALSE on failure. | |
*/ | |
function get($key); | |
/** | |
* Returns data from the key/value store when given an array of keys. | |
* | |
* @param $keys | |
* An array of keys for the data to retrieve. This is passed by | |
* reference, and will have the IDs successfully returned removed. | |
* | |
* @return | |
* An array of the items successfully returned, indexed by key. | |
*/ | |
function getMultiple(&$keys); | |
/** | |
* Stores data in the key/value store. | |
* | |
* @param $key | |
* The key of the data to store. | |
* @param $value | |
* The data to store. Complex data types will be automatically | |
* serialized before insertion. | |
* Strings will be stored as plain text and not serialized. | |
*/ | |
function set($key, $value); | |
/** | |
* Stores data in the key/value store. | |
* | |
* @param $data | |
* An array of key/value pairs. | |
*/ | |
function setMultiple($data); | |
/** | |
* Deletes an item. | |
* | |
* @param $key | |
* The key to delete. | |
*/ | |
function delete($key); | |
/** | |
* Deletes multiple items from the key/value store. | |
* | |
* @param $keys | |
* An array of $keys to delete. | |
*/ | |
function deleteMultiple(Array $keys); | |
} | |
class ConfigFileKeyValue implements KeyValueInterface { | |
static private $config_dir; | |
private $name; | |
private $data; | |
function __construct($name) { | |
$this->config_dir = config_get_config_directory(); | |
$this->name = $name; | |
$data = file_get_contents($config_dir . '/' . $name . '.xml'); | |
$this->data = decode($data); | |
} | |
function get($key) { | |
return $data[$key]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment