From cbcfc9cc4f52c8afb8a8d337774249778dbfae58 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Fri, 19 Sep 2008 02:52:59 +0000 Subject: [PATCH] Removed the final hardcoded paths, changed the reload logic in the Config class, and updated the controller to pass the config file name, not the config file short name. git-svn-id: http://svn.cleancode.org/svn/pickles@54 4d10bc64-7434-11dc-a737-d2d0f8310089 --- Pickles.php | 4 ++-- classes/Config.php | 16 +++++++++++----- classes/Controller.php | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Pickles.php b/Pickles.php index 8d58c33..9911f88 100755 --- a/Pickles.php +++ b/Pickles.php @@ -2,8 +2,8 @@ date_default_timezone_set('America/New_York'); -define('PICKLES_PATH', getcwd() . '/../../pickles/'); -define('TEMP_PATH', '/tmp/smarty/' . $_SERVER['SERVER_NAME'] . '/'); +define('PICKLES_PATH', (phpversion() < 5.3 ? dirname(__FILE__) : __DIR__) . '/'); +define('TEMP_PATH', sys_get_temp_dir() . '/pickles/smarty/' . $_SERVER['SERVER_NAME'] . '/'); function __autoload($class) { $file = PICKLES_PATH . 'classes/' . str_replace('_', '/', $class) . '.php'; diff --git a/classes/Config.php b/classes/Config.php index 8ffb3c6..d7ab62b 100755 --- a/classes/Config.php +++ b/classes/Config.php @@ -23,11 +23,17 @@ class Config extends Singleton { return self::$instance; } - public function load($site) { - // @todo getting warnings on the filemtime - if (!isset($this->file) || @filemtime($this->file) > $this->timestamp) { - $file = PICKLES_PATH . 'config/' . $site . '.xml'; - + public function load($file) { + $load = true; + if (isset($this->file)) { + if (file_exists($this->file) && isset($this->timestamp)) { + if (filemtime($this->file) < $this->timestamp) { + $load = false; + } + } + } + + if ($load) { if (file_exists($file)) { $this->file = $file; diff --git a/classes/Controller.php b/classes/Controller.php index 9062fea..3f78798 100755 --- a/classes/Controller.php +++ b/classes/Controller.php @@ -14,7 +14,7 @@ class Controller extends Object { private $controller = null; */ - public function __construct($site, $controller = 'Web') { + public function __construct($file = '../config.xml', $controller = 'Web') { parent::__construct(); @@ -23,7 +23,7 @@ class Controller extends Object { // Load the config for the site passed in $this->config = Config::getInstance(); - $this->config->load($site); + $this->config->load($file); // Generate a generic "site down" message if ($this->config->get('disabled')) {