diff --git a/app/webroot/index.php b/app/webroot/index.php index 85335cb97..128c391bb 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -80,7 +80,7 @@ $Dispatcher=new Dispatcher(); $Dispatcher->dispatch($url); } - if (DEBUG) { + if (Configure::read() > 0) { echo ""; } ?> \ No newline at end of file diff --git a/cake/basics.php b/cake/basics.php index dabc05c9b..f6c2f04f7 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -566,7 +566,7 @@ * @param boolean $show_html If set to true, the method prints the debug data in a screen-friendly way. */ function debug($var = false, $showHtml = false) { - if (DEBUG) { + if (Configure::read() > 0) { print "\n
\n"; ob_start(); print_r($var); @@ -749,7 +749,7 @@ * @param array $var */ function pr($var) { - if (DEBUG > 0) { + if (Configure::read() > 0) { echo ""; print_r($var); echo ""; diff --git a/cake/bootstrap.php b/cake/bootstrap.php index 6c2288ab6..a19524964 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -93,15 +93,7 @@ if (!defined('PHP5')) { } } - if (DEBUG) { - error_reporting(E_ALL); - - if (function_exists('ini_set')) { - ini_set('display_errors', 1); - } - } else { - error_reporting(0); - } + Configure::write('debug', DEBUG); require CAKE . 'dispatcher.php'; diff --git a/cake/libs/configure.php b/cake/libs/configure.php index 95327f53f..6c9c148d5 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -91,6 +91,162 @@ class Configure extends Object { } return $instance[0]; } +/** + * Used to write a dynamic var in the Configure instance. + * + * Usage + * Configure::write('One.key1', 'value of the Configure::One[key1]'); + * Configure::write(array('One.key1' => 'value of the Configure::One[key1]')); + * Configure::write('One', array('key1'=>'value of the Configure::One[key1]', 'key2'=>'value of the Configure::One[key2]'); + * Configure::write(array('One.key1' => 'value of the Configure::One[key1]', 'One.key2' => 'value of the Configure::One[key2]')); + * + * + * @param array $config + * @return void + * @access public + */ + function write($config, $value = null){ + $_this =& Configure::getInstance(); + + if(!is_array($config) && $value !== null) { + $name = $_this->__configVarNames($config); + + if(count($name) > 1){ + $_this->{$name[0]}[$name[1]] = $value; + } else { + $_this->{$name[0]} = $value; + } + } else { + + foreach($config as $names => $value){ + $name = $_this->__configVarNames($names); + if(count($name) > 1){ + $_this->{$name[0]}[$name[1]] = $value; + } else { + $_this->{$name[0]} = $value; + } + } + } + + if ($config == 'debug' || (is_array($config) && in_array('debug', $config))) { + if ($_this->debug) { + error_reporting(E_ALL); + + if (function_exists('ini_set')) { + ini_set('display_errors', 1); + } + } else { + error_reporting(0); + } + } + } +/** + * Used to read Configure::$var + * + * Usage + * Configure::read('Name'); will return all values for Name + * Configure::read('Name.key'); will return only the value of Configure::Name[key] + * + * @param string $var + * @return string value of Configure::$var + * @access public + */ + function read($var = 'debug'){ + $_this =& Configure::getInstance(); + if($var === 'debug') { + if(!isset($_this->debug)){ + $_this->debug = DEBUG; + } + return $_this->debug; + } + + $name = $_this->__configVarNames($var); + if(count($name) > 1){ + return $_this->{$name[0]}[$name[1]]; + } else { + return $_this->{$name[0]}; + } + } +/** + * Used to delete a var from the Configure instance. + * + * Usage: + * Configure::delete('Name'); will delete the entire Configure::Name + * Configure::delete('Name.key'); will delete only the Configure::Name[key] + * + * @param string $var the var to be deleted + * @return void + * @access public + */ + function delete($var = null){ + $_this =& Configure::getInstance(); + + $name = $_this->__configVarNames($var); + if(count($name) > 1){ + unset($_this->{$name[0]}[$name[1]]); + } else { + unset($_this->{$name[0]}); + } + } +/** + * Will load a file from app/config/configure_file.php + * variables in the files should be formated like: + * $config['name'] = 'value'; + * These will be used to create dynamic Configure vars. + * + * Usage Configure::load('configure_file'); + * + * @param string $fileName name of file to load, extension must be .php and only the name should be used, not the extenstion + * @return Configure::write + * @access public + */ + function load($fileName) { + $_this =& Configure::getInstance(); + + if(config($fileName) === false) { + trigger_error("Configure::load() - $fileName.php not found", E_USER_WARNING); + return false; + } + if(!isset($config)){ + trigger_error("Configure::load() - no variable \$config found in $fileName.php", E_USER_WARNING); + return false; + } + return $_this->write($config); + } + +/** + * Used to determine the current version of CakePHP + * + * Usage Configure::version(); + * + * @return string Current version of CakePHP + * @access public + */ + function version() { + $_this =& Configure::getInstance(); + if(!isset($_this->Cake['version'])){ + require(CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php'); + $_this->write($config); + } + return $_this->Cake['version']; + } +/** + * Checks $name for dot notation to create dynamic Configure::$var as an array when needed. + * + * @param mixed $name + * @return array + * @access private + */ + function __configVarNames($name) { + if (is_string($name)) { + if (strpos($name, ".")) { + $name = explode(".", $name); + } else { + $name = array($name); + } + } + return $name; + } /** * Sets the var modelPaths * diff --git a/cake/libs/error.php b/cake/libs/error.php index ec2c59310..666636711 100644 --- a/cake/libs/error.php +++ b/cake/libs/error.php @@ -76,7 +76,7 @@ class ErrorHandler extends Object{ $this->controller =& new Controller(); $this->controller->cacheAction = false; } - if (DEBUG > 0 || $method == 'error') { + if (Configure::read() > 0 || $method == 'error') { call_user_func_array(array(&$this, $method), $messages); } else { call_user_func_array(array(&$this, 'error404'), $messages); diff --git a/cake/libs/model/datasources/dbo/dbo_pear.php b/cake/libs/model/datasources/dbo/dbo_pear.php index 218cdd05f..1bcc187f0 100644 --- a/cake/libs/model/datasources/dbo/dbo_pear.php +++ b/cake/libs/model/datasources/dbo/dbo_pear.php @@ -62,7 +62,7 @@ class DboPear extends DboSource{ $this->config =$config; $dsn =$config['driver'] . '://' . $config['login'] . ':' . $config['password'] . '@' . $config['host'] . '/' . $config['database']; - $options=array('debug' => DEBUG - 1, + $options=array('debug' => Configure::read() - 1, 'portability' => DB_PORTABILITY_ALL,); $this->_pear =&DB::connect($dsn, $options); diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 4450a3ba1..28b44027e 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -81,8 +81,8 @@ class DboSource extends DataSource { * Constructor */ function __construct($config = null, $autoConnect = true) { - $this->debug = DEBUG > 0; - $this->fullDebug = DEBUG > 1; + $this->debug = Configure::read() > 0; + $this->fullDebug = Configure::read() > 1; parent::__construct($config); if ($autoConnect) { @@ -135,7 +135,7 @@ class DboSource extends DataSource { return $this->__sources; } - if (DEBUG > 0) { + if (Configure::read() > 0) { $expires = "+30 seconds"; } else { $expires = "+999 days"; @@ -670,7 +670,7 @@ class DboSource extends DataSource { if ($query) { if (!isset($resultSet) || !is_array($resultSet)) { - if (DEBUG) { + if (Configure::read() > 0) { e('SQL Error in model ' . $model->name . ': '); if (isset($this->error) && $this->error != null) { e($this->error); diff --git a/cake/libs/view/templates/layouts/flash.ctp b/cake/libs/view/templates/layouts/flash.ctp index 2a59a66df..8af4e7565 100644 --- a/cake/libs/view/templates/layouts/flash.ctp +++ b/cake/libs/view/templates/layouts/flash.ctp @@ -29,7 +29,7 @@- +