Modifications to make RippingCluster code work

This commit is contained in:
2011-04-21 23:33:21 +01:00
parent 998a9d958f
commit 177ed337b0
7 changed files with 29 additions and 22 deletions

View File

@@ -19,8 +19,11 @@ class SihnonFramework_Database {
private $prepared_statements = array(); private $prepared_statements = array();
public function __construct($dbconfig) { public function __construct($dbconfig) {
$this->database_cconfig = parse_ini_file($dbconfig); if ( ! file_exists($dbconfig)) {
var_dump($this->database_config); throw new SihnonFramework_Exception_DatabaseConfigMissing("config file not found");
}
$this->database_config = parse_ini_file($dbconfig);
$this->hostname = $this->getDatabaseConfig('hostname'); $this->hostname = $this->getDatabaseConfig('hostname');
$this->username = $this->getDatabaseConfig('username'); $this->username = $this->getDatabaseConfig('username');

View File

@@ -2,6 +2,9 @@
class SihnonFramework_Exception extends Exception {}; class SihnonFramework_Exception extends Exception {};
class SihnonFramework_Exception_NotInitialised extends SihnonFramework_Exception {};
class SihnonFramework_Exception_AlreadyInitialisted extends SihnonFramework_Exception {};
class SihnonFramework_Exception_NotImplemented extends SihnonFramework_Exception {}; class SihnonFramework_Exception_NotImplemented extends SihnonFramework_Exception {};
class SihnonFramework_Exception_MissingDefinition extends SihnonFramework_Exception {}; class SihnonFramework_Exception_MissingDefinition extends SihnonFramework_Exception {};

View File

@@ -19,10 +19,6 @@ class SihnonFramework_Log {
$this->log(self::LEVEL_INFO, "Logging started"); $this->log(self::LEVEL_INFO, "Logging started");
} }
public function __destruct() {
$this->log(self::LEVEL_INFO, "Logging shutdown");
}
public function log($level, $message) { public function log($level, $message) {
$this->backend->log($level, time(), 0, self::$hostname, $this->progname, 0, $message); $this->backend->log($level, time(), 0, self::$hostname, $this->progname, 0, $message);
} }

View File

@@ -25,7 +25,8 @@ abstract class SihnonFramework_LogEntry {
} }
public static function fromDatabaseRow($row) { public static function fromDatabaseRow($row) {
return new Sihnon_ClientLogEntry( $called_class = get_called_class();
return new $called_class(
$row['id'], $row['id'],
$row['level'], $row['level'],
$row['ctime'], $row['ctime'],
@@ -38,9 +39,10 @@ abstract class SihnonFramework_LogEntry {
} }
public static function fromId($id) { public static function fromId($id) {
$called_class = get_called_class();
$database = Sihnon_Main::instance()->database(); $database = Sihnon_Main::instance()->database();
return Sihnon_ClientLogEntry::fromDatabaseRow( return $called_class::fromDatabaseRow(
$database->selectOne('SELECT * FROM '.self::$table_name.' WHERE id=:id', array( $database->selectOne('SELECT * FROM '.static::$table_name.' WHERE id=:id', array(
array('name' => 'id', 'value' => $id, 'type' => PDO::PARAM_INT) array('name' => 'id', 'value' => $id, 'type' => PDO::PARAM_INT)
) )
) )
@@ -51,10 +53,10 @@ abstract class SihnonFramework_LogEntry {
$entries = array(); $entries = array();
$database = Sihnon_Main::instance()->database(); $database = Sihnon_Main::instance()->database();
foreach ($database->selectList('SELECT * FROM '.self::$table_name.' ORDER BY ctime DESC LIMIT :limit', array( foreach ($database->selectList('SELECT * FROM '.static::$table_name.' ORDER BY ctime DESC LIMIT :limit', array(
array('name' => 'limit', 'value' => $limit, 'type' => PDO::PARAM_INT) array('name' => 'limit', 'value' => $limit, 'type' => PDO::PARAM_INT)
)) as $row) { )) as $row) {
$entries[] = self::fromDatabaseRow($row); $entries[] = static::fromDatabaseRow($row);
} }
return $entries; return $entries;

View File

@@ -48,7 +48,8 @@ class SihnonFramework_Main {
*/ */
public static function instance() { public static function instance() {
if (!self::$instance) { if (!self::$instance) {
self::$instance = new Sihnon_Main(); $called_class = get_called_class();
self::$instance = new $called_class();
self::$instance->init(); self::$instance->init();
} }

View File

@@ -27,11 +27,11 @@ class SihnonFramework_Page {
try { try {
$this->render($template_filename, $code_filename, $template_variables); $this->render($template_filename, $code_filename, $template_variables);
} catch (MediaListing_Exception_AbortEntirePage $e) { } catch (SihnonFramework_Exception_AbortEntirePage $e) {
return false; return false;
} catch (MediaListing_Exception_FileNotFound $e) { } catch (SihnonFramework_Exception_FileNotFound $e) {
$this->render('errors/404.tpl', 'errors/404.php'); $this->render('errors/404.tpl', 'errors/404.php');
} catch (MediaListing_Exception $e) { } catch (SihnonFramework_Exception $e) {
$this->render('errors/unhandled-exception.tpl', 'errors/unhandled-exception.php', array( $this->render('errors/unhandled-exception.tpl', 'errors/unhandled-exception.php', array(
'exception' => $e, 'exception' => $e,
)); ));
@@ -41,8 +41,8 @@ class SihnonFramework_Page {
} }
protected function render($template_filename, $code_filename = null, $template_variables = array()) { protected function render($template_filename, $code_filename = null, $template_variables = array()) {
if ( ! $this->smarty->template_exists($template_filename)) { if ( ! $this->smarty->templateExists($template_filename)) {
throw new MediaListing_Exception_FileNotFound($template_filename); throw new SihnonFramework_Exception_FileNotFound($template_filename);
} }
// Copy all the template variables into the namespace for this function, // Copy all the template variables into the namespace for this function,
@@ -52,21 +52,23 @@ class SihnonFramework_Page {
} }
// Include the template code file, which will do all the work for this page // Include the template code file, which will do all the work for this page
$real_code_filename = '../source/pages/' . $code_filename; $real_code_filename = './source/pages/' . $code_filename;
if ($code_filename && file_exists($real_code_filename)) { if ($code_filename && file_exists($real_code_filename)) {
include $real_code_filename; include $real_code_filename;
} }
$this->smarty->assign('requested_page', $this->page);
// Now execute the template itself, which will render the results of the code file // Now execute the template itself, which will render the results of the code file
$this->smarty->assign('page_content', $this->smarty->fetch($template_filename)); $this->smarty->assign('page_content', $this->smarty->fetch($template_filename));
} }
public static function redirect($relative_url) { public static function redirect($relative_url) {
$absolute_url = MediaListing_Main::instance()->absoluteUrl($relative_url); $absolute_url = SihnonFramework_Main::instance()->absoluteUrl($relative_url);
header("Location: $absolute_url"); header("Location: $absolute_url");
throw new MediaListing_Exception_AbortEntirePage(); throw new SihnonFramework_Exception_AbortEntirePage();
} }
}; };

View File

@@ -25,7 +25,7 @@ class SihnonFramework_RequestParser {
// Read through the components list looking for elements matching known directories and files // Read through the components list looking for elements matching known directories and files
// to determine which page this request is for // to determine which page this request is for
$base_dir = '../source/templates'; $base_dir = './source/templates';
while (true) { while (true) {
if ($components && ! $components[0]) { if ($components && ! $components[0]) {
// Skip over any empty components before we find a page // Skip over any empty components before we find a page
@@ -81,7 +81,7 @@ class SihnonFramework_RequestParser {
return $this->vars[$key]; return $this->vars[$key];
} }
if (is_string($default) && preg_match('/^[a-zA-Z_]+_Exception/', $default) && class_exists($default) && is_subclass_of($default, MediaListing_Exception)) { if (is_string($default) && preg_match('/^[a-zA-Z_]+_Exception/', $default) && class_exists($default) && is_subclass_of($default, SihnonFramework_Exception)) {
throw new $default(); throw new $default();
} }