Changing Configure::read() to not have a default value, and instead return all values in configure when no param is supplied. Test cases updated. Fixes #503

This commit is contained in:
mark_story 2010-07-05 21:50:36 -04:00
parent 2fee0b5b63
commit 02e25f7557
12 changed files with 38 additions and 38 deletions

View file

@ -91,7 +91,7 @@
* @link http://book.cakephp.org/view/1128/debug * @link http://book.cakephp.org/view/1128/debug
*/ */
function debug($var = false, $showHtml = false, $showFrom = true) { function debug($var = false, $showHtml = false, $showFrom = true) {
if (Configure::read() > 0) { if (Configure::read('debug') > 0) {
if ($showFrom) { if ($showFrom) {
$calledFrom = debug_backtrace(); $calledFrom = debug_backtrace();
echo '<strong>' . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . '</strong>'; echo '<strong>' . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . '</strong>';
@ -197,7 +197,7 @@ if (!function_exists('sortByKey')) {
* @link http://book.cakephp.org/view/1136/pr * @link http://book.cakephp.org/view/1136/pr
*/ */
function pr($var) { function pr($var) {
if (Configure::read() > 0) { if (Configure::read('debug') > 0) {
echo '<pre>'; echo '<pre>';
print_r($var); print_r($var);
echo '</pre>'; echo '</pre>';

View file

@ -25,23 +25,16 @@
* @subpackage cake.cake.libs * @subpackage cake.cake.libs
* @link http://book.cakephp.org/view/924/The-Configuration-Class * @link http://book.cakephp.org/view/924/The-Configuration-Class
*/ */
class Configure extends Object { class Configure {
/**
* Current debug level.
*
* @link http://book.cakephp.org/view/931/CakePHP-Core-Configuration-Variables
* @var integer
* @access public
*/
public $debug = 0;
/** /**
* Array of values currently stored in Configure. * Array of values currently stored in Configure.
* *
* @var array * @var array
*/ */
protected static $_values = array(); protected static $_values = array(
'debug' => 0
);
/** /**
* Initializes configure and runs the bootstrap process. * Initializes configure and runs the bootstrap process.
@ -147,11 +140,13 @@ class Configure extends Object {
* @param string $var Variable to obtain. Use '.' to access array elements. * @param string $var Variable to obtain. Use '.' to access array elements.
* @return string value of Configure::$var * @return string value of Configure::$var
*/ */
public static function read($var = 'debug') { public static function read($var = null) {
if ($var === 'debug') { if ($var === null) {
return self::$_values['debug']; return self::$_values;
}
if (isset(self::$_values[$var])) {
return self::$_values[$var];
} }
if (strpos($var, '.') !== false) { if (strpos($var, '.') !== false) {
$names = explode('.', $var, 3); $names = explode('.', $var, 3);
$var = $names[0]; $var = $names[0];
@ -159,9 +154,6 @@ class Configure extends Object {
if (!isset(self::$_values[$var])) { if (!isset(self::$_values[$var])) {
return null; return null;
} }
if (!isset($names[1])) {
return self::$_values[$var];
}
switch (count($names)) { switch (count($names)) {
case 2: case 2:
if (isset(self::$_values[$var][$names[1]])) { if (isset(self::$_values[$var][$names[1]])) {
@ -315,7 +307,7 @@ class Configure extends Object {
private static function __writeConfig($content, $name, $write = true) { private static function __writeConfig($content, $name, $write = true) {
$file = CACHE . 'persistent' . DS . $name . '.php'; $file = CACHE . 'persistent' . DS . $name . '.php';
if (Configure::read() > 0) { if (Configure::read('debug') > 0) {
$expires = "+10 seconds"; $expires = "+10 seconds";
} else { } else {
$expires = "+999 days"; $expires = "+999 days";
@ -369,7 +361,7 @@ class Configure extends Object {
$prefix = $cache['settings']['prefix']; $prefix = $cache['settings']['prefix'];
} }
if (Configure::read() >= 1) { if (Configure::read('debug') >= 1) {
$duration = '+10 seconds'; $duration = '+10 seconds';
} else { } else {
$duration = '+999 days'; $duration = '+999 days';

View file

@ -291,7 +291,7 @@ class AuthComponent extends Object {
} }
} }
$this->_set($settings); $this->_set($settings);
if (Configure::read() > 0) { if (Configure::read('debug') > 0) {
App::import('Debugger'); App::import('Debugger');
Debugger::checkSecurityKeys(); Debugger::checkSecurityKeys();
} }
@ -307,7 +307,7 @@ class AuthComponent extends Object {
public function startup(&$controller) { public function startup(&$controller) {
$isErrorOrTests = ( $isErrorOrTests = (
strtolower($controller->name) == 'cakeerror' || strtolower($controller->name) == 'cakeerror' ||
(strtolower($controller->name) == 'tests' && Configure::read() > 0) (strtolower($controller->name) == 'tests' && Configure::read('debug') > 0)
); );
if ($isErrorOrTests) { if ($isErrorOrTests) {
return true; return true;

View file

@ -718,7 +718,7 @@ class RequestHandlerComponent extends Object {
if (!empty($options['attachment'])) { if (!empty($options['attachment'])) {
$this->_header("Content-Disposition: attachment; filename=\"{$options['attachment']}\""); $this->_header("Content-Disposition: attachment; filename=\"{$options['attachment']}\"");
} }
if (Configure::read() < 2 && !defined('CAKEPHP_SHELL')) { if (Configure::read('debug') < 2 && !defined('CAKEPHP_SHELL')) {
$this->_header($header); $this->_header($header);
} }
$this->__responseTypeSet = $cType; $this->__responseTypeSet = $cType;

View file

@ -826,7 +826,7 @@ class Controller extends Object {
$this->params['models'] = $this->modelNames; $this->params['models'] = $this->modelNames;
if (Configure::read() > 2) { if (Configure::read('debug') > 2) {
$this->set('cakeDebug', $this); $this->set('cakeDebug', $this);
} }

View file

@ -181,7 +181,7 @@ class Debugger {
if (!empty($class)) { if (!empty($class)) {
if (!$instance || strtolower($class) != strtolower(get_class($instance[0]))) { if (!$instance || strtolower($class) != strtolower(get_class($instance[0]))) {
$instance[0] = & new $class(); $instance[0] = & new $class();
if (Configure::read() > 0) { if (Configure::read('debug') > 0) {
Configure::version(); // Make sure the core config is loaded Configure::version(); // Make sure the core config is loaded
$instance[0]->helpPath = Configure::read('Cake.Debugger.HelpPath'); $instance[0]->helpPath = Configure::read('Cake.Debugger.HelpPath');
} }
@ -190,7 +190,7 @@ class Debugger {
if (!$instance) { if (!$instance) {
$instance[0] =& new Debugger(); $instance[0] =& new Debugger();
if (Configure::read() > 0) { if (Configure::read('debug') > 0) {
Configure::version(); // Make sure the core config is loaded Configure::version(); // Make sure the core config is loaded
$instance[0]->helpPath = Configure::read('Cake.Debugger.HelpPath'); $instance[0]->helpPath = Configure::read('Cake.Debugger.HelpPath');
} }

View file

@ -977,7 +977,7 @@ class DboOracle extends DboSource {
function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) { function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) {
if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) { if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) {
if (!isset($resultSet) || !is_array($resultSet)) { if (!isset($resultSet) || !is_array($resultSet)) {
if (Configure::read() > 0) { if (Configure::read('debug') > 0) {
echo '<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:'), $model->alias) . ' '; echo '<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:'), $model->alias) . ' ';
if (isset($this->error) && $this->error != null) { if (isset($this->error) && $this->error != null) {
echo $this->error; echo $this->error;

View file

@ -134,7 +134,7 @@ class DboSource extends DataSource {
$config['prefix'] = ''; $config['prefix'] = '';
} }
parent::__construct($config); parent::__construct($config);
$this->fullDebug = Configure::read() > 1; $this->fullDebug = Configure::read('debug') > 1;
if (!$this->enabled()) { if (!$this->enabled()) {
return false; return false;
} }
@ -651,10 +651,10 @@ class DboSource extends DataSource {
*/ */
public function showQuery($sql) { public function showQuery($sql) {
$error = $this->error; $error = $this->error;
if (strlen($sql) > 200 && !$this->fullDebug && Configure::read() > 1) { if (strlen($sql) > 200 && !$this->fullDebug && Configure::read('debug') > 1) {
$sql = substr($sql, 0, 200) . '[...]'; $sql = substr($sql, 0, 200) . '[...]';
} }
if (Configure::read() > 0) { if (Configure::read('debug') > 0) {
$out = null; $out = null;
if ($error) { if ($error) {
trigger_error('<span style="color:Red;text-align:left"><b>' . __('SQL Error:') . "</b> {$this->error}</span>", E_USER_WARNING); trigger_error('<span style="color:Red;text-align:left"><b>' . __('SQL Error:') . "</b> {$this->error}</span>", E_USER_WARNING);
@ -889,7 +889,7 @@ class DboSource extends DataSource {
public function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) { public function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) {
if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) { if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) {
if (!isset($resultSet) || !is_array($resultSet)) { if (!isset($resultSet) || !is_array($resultSet)) {
if (Configure::read() > 0) { if (Configure::read('debug') > 0) {
echo '<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:'), $model->alias) . ' '; echo '<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:'), $model->alias) . ' ';
if (isset($this->error) && $this->error != null) { if (isset($this->error) && $this->error != null) {
echo $this->error; echo $this->error;

View file

@ -229,7 +229,7 @@ class Object {
$data = str_replace('\\', '\\\\', serialize($objectArray)); $data = str_replace('\\', '\\\\', serialize($objectArray));
$data = '<?php $' . $name . ' = \'' . str_replace('\'', '\\\'', $data) . '\' ?>'; $data = '<?php $' . $name . ' = \'' . str_replace('\'', '\\\'', $data) . '\' ?>';
$duration = '+999 days'; $duration = '+999 days';
if (Configure::read() >= 1) { if (Configure::read('debug') >= 1) {
$duration = '+10 seconds'; $duration = '+10 seconds';
} }
cache($file, $data, $duration); cache($file, $data, $duration);

View file

@ -237,7 +237,7 @@ class Helper extends Object {
*/ */
public function assetTimestamp($path) { public function assetTimestamp($path) {
$timestampEnabled = ( $timestampEnabled = (
(Configure::read('Asset.timestamp') === true && Configure::read() > 0) || (Configure::read('Asset.timestamp') === true && Configure::read('debug') > 0) ||
Configure::read('Asset.timestamp') === 'force' Configure::read('Asset.timestamp') === 'force'
); );
if (strpos($path, '?') === false && $timestampEnabled) { if (strpos($path, '?') === false && $timestampEnabled) {

View file

@ -389,7 +389,7 @@ class View extends Object {
} }
$file = $paths[0] . 'elements' . DS . $name . $this->ext; $file = $paths[0] . 'elements' . DS . $name . $this->ext;
if (Configure::read() > 0) { if (Configure::read('debug') > 0) {
return "Not Found: " . $file; return "Not Found: " . $file;
} }
} }
@ -524,7 +524,7 @@ class View extends Object {
ob_start(); ob_start();
include ($filename); include ($filename);
if (Configure::read() > 0 && $this->layout != 'xml') { if (Configure::read('debug') > 0 && $this->layout != 'xml') {
echo "<!-- Cached Render Time: " . round(microtime(true) - $timeStart, 4) . "s -->"; echo "<!-- Cached Render Time: " . round(microtime(true) - $timeStart, 4) . "s -->";
} }
$out = ob_get_clean(); $out = ob_get_clean();
@ -707,7 +707,7 @@ class View extends Object {
extract($___dataForView, EXTR_SKIP); extract($___dataForView, EXTR_SKIP);
ob_start(); ob_start();
if (Configure::read() > 0) { if (Configure::read('debug') > 0) {
include ($___viewFn); include ($___viewFn);
} else { } else {
@include ($___viewFn); @include ($___viewFn);

View file

@ -99,6 +99,14 @@ class ConfigureTest extends CakeTestCase {
$result = Configure::read('debug'); $result = Configure::read('debug');
$this->assertTrue($result >= 0); $this->assertTrue($result >= 0);
$result = Configure::read();
$this->assertTrue(is_array($result));
$this->assertTrue(isset($result['debug']));
$this->assertTrue(isset($result['level1']));
$result = Configure::read('something_I_just_made_up_now');
$this->assertEquals(null, $result, 'Missing key should return null.');
} }
/** /**