diff --git a/source/lib/SihnonFramework/Database.class.php b/source/lib/SihnonFramework/Database.class.php index 61978f6..30e2d7b 100644 --- a/source/lib/SihnonFramework/Database.class.php +++ b/source/lib/SihnonFramework/Database.class.php @@ -19,8 +19,11 @@ class SihnonFramework_Database { private $prepared_statements = array(); public function __construct($dbconfig) { - $this->database_cconfig = parse_ini_file($dbconfig); - var_dump($this->database_config); + if ( ! file_exists($dbconfig)) { + throw new SihnonFramework_Exception_DatabaseConfigMissing("config file not found"); + } + + $this->database_config = parse_ini_file($dbconfig); $this->hostname = $this->getDatabaseConfig('hostname'); $this->username = $this->getDatabaseConfig('username'); diff --git a/source/lib/SihnonFramework/Exceptions.class.php b/source/lib/SihnonFramework/Exceptions.class.php index e2ad85a..241ee73 100644 --- a/source/lib/SihnonFramework/Exceptions.class.php +++ b/source/lib/SihnonFramework/Exceptions.class.php @@ -2,6 +2,9 @@ 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_MissingDefinition extends SihnonFramework_Exception {}; diff --git a/source/lib/SihnonFramework/Log.class.php b/source/lib/SihnonFramework/Log.class.php index 693f610..dd1f888 100644 --- a/source/lib/SihnonFramework/Log.class.php +++ b/source/lib/SihnonFramework/Log.class.php @@ -19,10 +19,6 @@ class SihnonFramework_Log { $this->log(self::LEVEL_INFO, "Logging started"); } - public function __destruct() { - $this->log(self::LEVEL_INFO, "Logging shutdown"); - } - public function log($level, $message) { $this->backend->log($level, time(), 0, self::$hostname, $this->progname, 0, $message); } diff --git a/source/lib/SihnonFramework/LogEntry.class.php b/source/lib/SihnonFramework/LogEntry.class.php index b3494f6..04ceec0 100644 --- a/source/lib/SihnonFramework/LogEntry.class.php +++ b/source/lib/SihnonFramework/LogEntry.class.php @@ -25,7 +25,8 @@ abstract class SihnonFramework_LogEntry { } public static function fromDatabaseRow($row) { - return new Sihnon_ClientLogEntry( + $called_class = get_called_class(); + return new $called_class( $row['id'], $row['level'], $row['ctime'], @@ -38,9 +39,10 @@ abstract class SihnonFramework_LogEntry { } public static function fromId($id) { + $called_class = get_called_class(); $database = Sihnon_Main::instance()->database(); - return Sihnon_ClientLogEntry::fromDatabaseRow( - $database->selectOne('SELECT * FROM '.self::$table_name.' WHERE id=:id', array( + return $called_class::fromDatabaseRow( + $database->selectOne('SELECT * FROM '.static::$table_name.' WHERE id=:id', array( array('name' => 'id', 'value' => $id, 'type' => PDO::PARAM_INT) ) ) @@ -51,10 +53,10 @@ abstract class SihnonFramework_LogEntry { $entries = array(); $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) )) as $row) { - $entries[] = self::fromDatabaseRow($row); + $entries[] = static::fromDatabaseRow($row); } return $entries; diff --git a/source/lib/SihnonFramework/Main.class.php b/source/lib/SihnonFramework/Main.class.php index 914a569..c0b7d1e 100644 --- a/source/lib/SihnonFramework/Main.class.php +++ b/source/lib/SihnonFramework/Main.class.php @@ -48,7 +48,8 @@ class SihnonFramework_Main { */ public static function instance() { if (!self::$instance) { - self::$instance = new Sihnon_Main(); + $called_class = get_called_class(); + self::$instance = new $called_class(); self::$instance->init(); } diff --git a/source/lib/SihnonFramework/Page.class.php b/source/lib/SihnonFramework/Page.class.php index 9d0f401..37b51c4 100644 --- a/source/lib/SihnonFramework/Page.class.php +++ b/source/lib/SihnonFramework/Page.class.php @@ -27,11 +27,11 @@ class SihnonFramework_Page { try { $this->render($template_filename, $code_filename, $template_variables); - } catch (MediaListing_Exception_AbortEntirePage $e) { + } catch (SihnonFramework_Exception_AbortEntirePage $e) { return false; - } catch (MediaListing_Exception_FileNotFound $e) { + } catch (SihnonFramework_Exception_FileNotFound $e) { $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( 'exception' => $e, )); @@ -41,8 +41,8 @@ class SihnonFramework_Page { } protected function render($template_filename, $code_filename = null, $template_variables = array()) { - if ( ! $this->smarty->template_exists($template_filename)) { - throw new MediaListing_Exception_FileNotFound($template_filename); + if ( ! $this->smarty->templateExists($template_filename)) { + throw new SihnonFramework_Exception_FileNotFound($template_filename); } // 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 - $real_code_filename = '../source/pages/' . $code_filename; + $real_code_filename = './source/pages/' . $code_filename; if ($code_filename && file_exists($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 $this->smarty->assign('page_content', $this->smarty->fetch($template_filename)); } 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"); - throw new MediaListing_Exception_AbortEntirePage(); + throw new SihnonFramework_Exception_AbortEntirePage(); } }; diff --git a/source/lib/SihnonFramework/RequestParser.class.php b/source/lib/SihnonFramework/RequestParser.class.php index 8532939..c37613a 100644 --- a/source/lib/SihnonFramework/RequestParser.class.php +++ b/source/lib/SihnonFramework/RequestParser.class.php @@ -25,7 +25,7 @@ class SihnonFramework_RequestParser { // Read through the components list looking for elements matching known directories and files // to determine which page this request is for - $base_dir = '../source/templates'; + $base_dir = './source/templates'; while (true) { if ($components && ! $components[0]) { // Skip over any empty components before we find a page @@ -81,7 +81,7 @@ class SihnonFramework_RequestParser { 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(); }