From 47b3271bdef835385220aa9d43ef33cd1372940b Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Wed, 15 Oct 2008 12:51:26 +0000 Subject: [PATCH] Updates. git-svn-id: http://svn.cleancode.org/svn/pickles@76 4d10bc64-7434-11dc-a737-d2d0f8310089 --- classes/Config.php | 13 +++++++++++++ classes/Controller.php | 15 ++++++++++----- classes/DB.php | 11 +++++++++++ classes/Logger.php | 4 ++-- classes/Viewer/PHP.php | 10 +++++----- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/classes/Config.php b/classes/Config.php index 77be6f5..65664c8 100755 --- a/classes/Config.php +++ b/classes/Config.php @@ -103,6 +103,19 @@ class Config extends Object { return false; } + /** + * Gets the authentication value + * + * @return boolean The model's authentication setting or false + */ + public function getDebug() { + if (isset($this->models->debug) && $this->models->debug == 'true') { + return true; + } + + return false; + } + /** * Alias for $config->models->default with string cast * diff --git a/classes/Controller.php b/classes/Controller.php index 2f46717..1e373e0 100755 --- a/classes/Controller.php +++ b/classes/Controller.php @@ -54,7 +54,7 @@ class Controller extends Object { // Check the passed config variables object type if (is_object($config)) { if ($config instanceof Config === false) { - $error->setWarning('Passed object is not an instance of Config'); + $error->addWarning('Passed object is not an instance of Config'); $config = null; } } @@ -68,13 +68,18 @@ class Controller extends Object { $filename = $config; } else { - $error->setWarning('Passed config filename does not exist'); - $config = null; + $error->addWarning('Passed config filename does not exist'); } } + else { + $config = null; + } // If no Config object is passed (or it's cleared), create a new one from assumptions if ($config == null) { + $config = new Config(); + } + else { $config = new Config($filename); } @@ -185,7 +190,7 @@ class Controller extends Object { $viewer = new $viewer_class($config, $error); } else { - $error->setError('Invalid viewer specified (' . $viewer_name . ')'); + $error->addError('Invalid viewer specified (' . $viewer_name . ')'); } // Sets the viewers properties @@ -203,7 +208,7 @@ class Controller extends Object { } unset($model, $viewer); - unset($db, $mailer, $config, $error, $logger) + unset($db, $mailer, $config, $error, $logger); } } } diff --git a/classes/DB.php b/classes/DB.php index 298ebfc..252ac24 100755 --- a/classes/DB.php +++ b/classes/DB.php @@ -136,6 +136,7 @@ class DB extends Object { * * @param string $sql SQL statement to be executed * @return boolean Returns the status of the execution + * @todo The code to break apart the SQL is very primitive, needs some lovin' */ public function execute($sql) { $this->open(); @@ -148,6 +149,16 @@ class DB extends Object { $this->error->addError(mysql_error()); } else { + // Grabs the table name + $explain = mysql_query('EXPLAIN ' . $sql, $this->connection); + $results = mysql_fetch_array($explain, MYSQL_ASSOC); + + // Grabs the model's name that made the call + $backtrace = debug_backtrace(); + $model_name = $backtrace[2]['class']; + + //var_dump($results['table'], $model_name); + return true; } } diff --git a/classes/Logger.php b/classes/Logger.php index 8fa8cc8..7794c84 100644 --- a/classes/Logger.php +++ b/classes/Logger.php @@ -33,10 +33,10 @@ class Logger extends Object { parent::__construct(); } - public function write($type, $message) { + public function write($type, $message, $class = null) { if (!file_exists(LOG_PATH)) { mkdir(LOG_PATH, 0777, true); } - $message = '[' . date('r') . '] [client ' . $_SERVER['REMOTE_ADDR'] . '] [uri ' . $_SERVER['REQUEST_URI'] . '] [script ' . $_SERVER['SCRIPT_NAME'] . (isset($$_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '') . '] ' . $message; + $message = '[' . date('r') . '] [client ' . $_SERVER['REMOTE_ADDR'] . '] [uri ' . $_SERVER['REQUEST_URI'] . '] [script ' . $_SERVER['SCRIPT_NAME'] . '] ' . $message; file_put_contents(LOG_PATH . $type . '.log', $message . "\n", FILE_APPEND); } diff --git a/classes/Viewer/PHP.php b/classes/Viewer/PHP.php index 45f2c8c..cd41bd4 100644 --- a/classes/Viewer/PHP.php +++ b/classes/Viewer/PHP.php @@ -60,15 +60,15 @@ class Viewer_PHP extends Viewer_Common { /** * @todo Section or model needs to go, having both seems dumb. */ - $section = $this->model->section; - $model = $this->model->name; - $template = $template; + $section = $this->section; + $model = $this->model_name; + $template = $this->template; // Loads the data from the config $config = $this->config->getPublicData(); // Loads the data from the model - $data = $this->model->getData(); + $data = $this->data; // If there's data set, this brings it into scope if (isset($this->data) && is_array($this->data)) { @@ -83,7 +83,7 @@ class Viewer_PHP extends Viewer_Common { if (file_exists(SITE_PATH . '../templates/index.php')) { require_once SITE_PATH . '../templates/index.php'; } - else if (file_exists{$this->template)) { + else if (file_exists($this->template)) { require_once $this->template; }