Implements Config and Logging plugins, tidies Main

Added Database and Flatfile plugin engines for both Config and Log classes.
Rewrote Main to make use of the new plugins.
Updated config file definitions to make use of plugins.
This commit is contained in:
2010-10-10 17:11:44 +01:00
parent ddd2e62c13
commit 676fef1deb
15 changed files with 408 additions and 112 deletions

View File

@@ -0,0 +1,29 @@
<?php
interface Sihnon_Config_IPlugin extends Sihnon_IPlugin {
/**
* Returns a new instance of the Plugin class
*
* @param array(string=>mixed) $options Configuration options for the Plugin object
*/
public static function create($options);
/**
* Loads all the configuration items from the storage backend
*
* @param string $source_filename Filename of the source
* @param bool $scan Request that the source be scanned for content. Defaults to true.
* @param bool $use_cache Request that the cache be used. Defaults to true.
* @return RippingCluster_Source
*/
public function preload();
/**
* Saves the value of all configuration items back into the storage backend
*/
public function save();
}
?>

View File

@@ -0,0 +1,33 @@
<?php
class Sihnon_Config_Plugin_Database extends Sihnon_PluginBase implements Sihnon_Config_IPlugin {
/**
* Name of this plugin
* @var string
*/
const PLUGIN_NAME = "Database";
private $database;
private $table;
protected function __construct($options) {
$this->database = $options['database'];
$this->table = $options['table'];
}
public static function create($options) {
return new self($options);
}
public function preload() {
return $this->database->selectAssoc("SELECT name,type,value FROM {$this->table}", 'name', array('name', 'value', 'type'));
}
public function save() {
throw new Sihnon_Exception_NotImplemented();
}
}
?>

View File

@@ -0,0 +1,31 @@
<?php
class Sihnon_Config_Plugin_FlatFile extends Sihnon_PluginBase implements Sihnon_Config_IPlugin {
/**
* Name of this plugin
* @var string
*/
const PLUGIN_NAME = "FlatFile";
protected $filename;
protected function __construct($options) {
$this->filename = $options['filename'];
}
public static function create($options) {
return new self($options);
}
public function preload() {
return parse_ini_file($this->filename, true);;
}
public function save() {
throw new Sihnon_Exception_NotImplemented();
}
}
?>

View File

@@ -0,0 +1,27 @@
<?php
class Sihnon_Config_PluginFactory extends Sihnon_PluginFactory {
const PLUGIN_DIR = 'Sihnon/Config/Plugin/';
const PLUGIN_PREFIX = 'Sihnon_Config_Plugin_';
const PLUGIN_INTERFACE = 'Sihnon_Config_IPlugin';
public static function init() {
}
public static function create($plugin, $options) {
self::ensureScanned();
if (! self::isValidPlugin($plugin)) {
throw new Sihnon_Exception_InvalidPluginName($plugin);
}
$classname = self::classname($plugin);
return call_user_func(array($classname, 'create'), $options);
}
}
?>