Adding new methods to Configure and moving all core messages using DEBUG to use Configure::read()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4069 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
dho 2006-12-05 09:49:59 +00:00
parent b72ab690d4
commit 9ca5e14891
11 changed files with 172 additions and 24 deletions

View file

@ -80,7 +80,7 @@
$Dispatcher=new Dispatcher(); $Dispatcher=new Dispatcher();
$Dispatcher->dispatch($url); $Dispatcher->dispatch($url);
} }
if (DEBUG) { if (Configure::read() > 0) {
echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->"; echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->";
} }
?> ?>

View file

@ -566,7 +566,7 @@
* @param boolean $show_html If set to true, the method prints the debug data in a screen-friendly way. * @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) { function debug($var = false, $showHtml = false) {
if (DEBUG) { if (Configure::read() > 0) {
print "\n<pre class=\"cake_debug\">\n"; print "\n<pre class=\"cake_debug\">\n";
ob_start(); ob_start();
print_r($var); print_r($var);
@ -749,7 +749,7 @@
* @param array $var * @param array $var
*/ */
function pr($var) { function pr($var) {
if (DEBUG > 0) { if (Configure::read() > 0) {
echo "<pre>"; echo "<pre>";
print_r($var); print_r($var);
echo "</pre>"; echo "</pre>";

View file

@ -93,15 +93,7 @@ if (!defined('PHP5')) {
} }
} }
if (DEBUG) { Configure::write('debug', DEBUG);
error_reporting(E_ALL);
if (function_exists('ini_set')) {
ini_set('display_errors', 1);
}
} else {
error_reporting(0);
}
require CAKE . 'dispatcher.php'; require CAKE . 'dispatcher.php';

View file

@ -91,6 +91,162 @@ class Configure extends Object {
} }
return $instance[0]; 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 * Sets the var modelPaths
* *

View file

@ -76,7 +76,7 @@ class ErrorHandler extends Object{
$this->controller =& new Controller(); $this->controller =& new Controller();
$this->controller->cacheAction = false; $this->controller->cacheAction = false;
} }
if (DEBUG > 0 || $method == 'error') { if (Configure::read() > 0 || $method == 'error') {
call_user_func_array(array(&$this, $method), $messages); call_user_func_array(array(&$this, $method), $messages);
} else { } else {
call_user_func_array(array(&$this, 'error404'), $messages); call_user_func_array(array(&$this, 'error404'), $messages);

View file

@ -62,7 +62,7 @@ class DboPear extends DboSource{
$this->config =$config; $this->config =$config;
$dsn =$config['driver'] . '://' . $config['login'] . ':' . $config['password'] . '@' $dsn =$config['driver'] . '://' . $config['login'] . ':' . $config['password'] . '@'
. $config['host'] . '/' . $config['database']; . $config['host'] . '/' . $config['database'];
$options=array('debug' => DEBUG - 1, $options=array('debug' => Configure::read() - 1,
'portability' => DB_PORTABILITY_ALL,); 'portability' => DB_PORTABILITY_ALL,);
$this->_pear =&DB::connect($dsn, $options); $this->_pear =&DB::connect($dsn, $options);

View file

@ -81,8 +81,8 @@ class DboSource extends DataSource {
* Constructor * Constructor
*/ */
function __construct($config = null, $autoConnect = true) { function __construct($config = null, $autoConnect = true) {
$this->debug = DEBUG > 0; $this->debug = Configure::read() > 0;
$this->fullDebug = DEBUG > 1; $this->fullDebug = Configure::read() > 1;
parent::__construct($config); parent::__construct($config);
if ($autoConnect) { if ($autoConnect) {
@ -135,7 +135,7 @@ class DboSource extends DataSource {
return $this->__sources; return $this->__sources;
} }
if (DEBUG > 0) { if (Configure::read() > 0) {
$expires = "+30 seconds"; $expires = "+30 seconds";
} else { } else {
$expires = "+999 days"; $expires = "+999 days";
@ -670,7 +670,7 @@ class DboSource extends DataSource {
if ($query) { if ($query) {
if (!isset($resultSet) || !is_array($resultSet)) { if (!isset($resultSet) || !is_array($resultSet)) {
if (DEBUG) { if (Configure::read() > 0) {
e('<div style = "font: Verdana bold 12px; color: #FF0000">SQL Error in model ' . $model->name . ': '); e('<div style = "font: Verdana bold 12px; color: #FF0000">SQL Error in model ' . $model->name . ': ');
if (isset($this->error) && $this->error != null) { if (isset($this->error) && $this->error != null) {
e($this->error); e($this->error);

View file

@ -29,7 +29,7 @@
<head> <head>
<title><?php echo $page_title?></title> <title><?php echo $page_title?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php if(DEBUG == 0) { ?> <?php if(Configure::read() == 0) { ?>
<meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/> <meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/>
<?php } ?> <?php } ?>
<style><!-- <style><!--

View file

@ -382,7 +382,7 @@ class View extends Object {
function renderLayout($content_for_layout) { function renderLayout($content_for_layout) {
$layout_fn = $this->_getLayoutFileName(); $layout_fn = $this->_getLayoutFileName();
if (DEBUG > 2 && $this->controller != null) { if (Configure::read() > 2 && $this->controller != null) {
$debug = View::_render(LIBS . 'view' . DS . 'templates' . DS . 'elements' . DS . 'dump.ctp', array('controller' => $this->controller), false); $debug = View::_render(LIBS . 'view' . DS . 'templates' . DS . 'elements' . DS . 'dump.ctp', array('controller' => $this->controller), false);
} else { } else {
$debug = ''; $debug = '';
@ -685,7 +685,7 @@ class View extends Object {
ob_start(); ob_start();
if (DEBUG) { if (Configure::read() > 0) {
include ($___viewFn); include ($___viewFn);
} else { } else {
@include ($___viewFn); @include ($___viewFn);
@ -797,7 +797,7 @@ class View extends Object {
ob_start(); ob_start();
include ($filename); include ($filename);
if (DEBUG && $this->layout != 'xml') { if (Configure::read() > 0 && $this->layout != 'xml') {
echo "<!-- Cached Render Time: " . round(getMicrotime() - $timeStart, 4) . "s -->"; echo "<!-- Cached Render Time: " . round(getMicrotime() - $timeStart, 4) . "s -->";
} }

View file

@ -33,7 +33,7 @@
<head> <head>
<title><?php echo $page_title?></title> <title><?php echo $page_title?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php if(DEBUG == 0) { ?> <?php if(Configure::read() == 0) { ?>
<meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/> <meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/>
<?php } ?> <?php } ?>
<style><!-- <style><!--

View file

@ -81,7 +81,7 @@
$Dispatcher=new Dispatcher(); $Dispatcher=new Dispatcher();
$Dispatcher->dispatch($url); $Dispatcher->dispatch($url);
} }
if (DEBUG) { if (Configure::read()) {
echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->"; echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->";
} }
?> ?>