git-svn-id: http://svn.cleancode.org/svn/pickles@76 4d10bc64-7434-11dc-a737-d2d0f8310089
This commit is contained in:
Josh Sherman 2008-10-15 12:51:26 +00:00
parent e0e0ab0aeb
commit 47b3271bde
5 changed files with 41 additions and 12 deletions

View file

@ -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
*

View file

@ -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);
}
}
}

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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;
}