Core class updates

Improved database abstraction class to support insert and select queries
in various forms.
Added classes for pulling log entries back out of the database.
Updated Job class to describe a known job in the database, and added
JobStatus to track status updates on jobs.
Updated Config class to connect to the database, and load all settings
on startup.
Improved the class autoloader to support Exceptions in a single file as
a special case, and added this file.
This commit is contained in:
2010-03-18 02:00:53 +00:00
parent 3603445a5b
commit a9ebf6e0cb
11 changed files with 541 additions and 9 deletions

View File

@@ -2,10 +2,53 @@
class HandBrakeCluster_Config {
private $filename;
private $dbconfig;
private $database;
public function __construct($filename) {
$this->filename = $filename;
private $databaseConfig = array();
private $settings = array();
public function __construct($dbconfig) {
$this->dbconfig = $dbconfig;
$this->parseDatabaseConfig();
}
public function parseDatabaseConfig() {
$this->databaseConfig = parse_ini_file($this->dbconfig);
}
public function getDatabase($key) {
if (!isset($this->databaseConfig[$key])) {
throw new HandBrakeCluster_Exception_DatabaseConfigMissing($key);
}
return $this->databaseConfig[$key];
}
public function setDatabase(HandBrakeCluster_Database $database) {
$this->database = $database;
$this->preload();
}
public function preload() {
if (!$this->database) {
throw new HandBrakeCluster_Exception_NoDatabaseConnection();
}
$this->settings = $this->database->selectAssoc('SELECT name,value FROM settings', 'name', 'value');
}
public function exists($key) {
return isset($this->settings[$key]);
}
public function get($key) {
if (!isset($this->settings[$key])) {
throw new HandBrakeCluster_Exception_UnknownSetting($key);
}
return $this->settings[$key];
}
};