Files
handbrake-cluster-webui/HandBrakeCluster/Config.class.php
Ben Roberts a9ebf6e0cb 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.
2010-03-18 02:00:53 +00:00

57 lines
1.3 KiB
PHP

<?php
class HandBrakeCluster_Config {
private $dbconfig;
private $database;
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];
}
};
?>