mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
2fee0b5b63
commit
02e25f7557
12 changed files with 38 additions and 38 deletions
|
@ -91,7 +91,7 @@
|
|||
* @link http://book.cakephp.org/view/1128/debug
|
||||
*/
|
||||
function debug($var = false, $showHtml = false, $showFrom = true) {
|
||||
if (Configure::read() > 0) {
|
||||
if (Configure::read('debug') > 0) {
|
||||
if ($showFrom) {
|
||||
$calledFrom = debug_backtrace();
|
||||
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
|
||||
*/
|
||||
function pr($var) {
|
||||
if (Configure::read() > 0) {
|
||||
if (Configure::read('debug') > 0) {
|
||||
echo '<pre>';
|
||||
print_r($var);
|
||||
echo '</pre>';
|
||||
|
|
|
@ -25,23 +25,16 @@
|
|||
* @subpackage cake.cake.libs
|
||||
* @link http://book.cakephp.org/view/924/The-Configuration-Class
|
||||
*/
|
||||
class Configure extends Object {
|
||||
|
||||
/**
|
||||
* Current debug level.
|
||||
*
|
||||
* @link http://book.cakephp.org/view/931/CakePHP-Core-Configuration-Variables
|
||||
* @var integer
|
||||
* @access public
|
||||
*/
|
||||
public $debug = 0;
|
||||
class Configure {
|
||||
|
||||
/**
|
||||
* Array of values currently stored in Configure.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_values = array();
|
||||
protected static $_values = array(
|
||||
'debug' => 0
|
||||
);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return string value of Configure::$var
|
||||
*/
|
||||
public static function read($var = 'debug') {
|
||||
if ($var === 'debug') {
|
||||
return self::$_values['debug'];
|
||||
public static function read($var = null) {
|
||||
if ($var === null) {
|
||||
return self::$_values;
|
||||
}
|
||||
if (isset(self::$_values[$var])) {
|
||||
return self::$_values[$var];
|
||||
}
|
||||
|
||||
if (strpos($var, '.') !== false) {
|
||||
$names = explode('.', $var, 3);
|
||||
$var = $names[0];
|
||||
|
@ -159,9 +154,6 @@ class Configure extends Object {
|
|||
if (!isset(self::$_values[$var])) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($names[1])) {
|
||||
return self::$_values[$var];
|
||||
}
|
||||
switch (count($names)) {
|
||||
case 2:
|
||||
if (isset(self::$_values[$var][$names[1]])) {
|
||||
|
@ -315,7 +307,7 @@ class Configure extends Object {
|
|||
private static function __writeConfig($content, $name, $write = true) {
|
||||
$file = CACHE . 'persistent' . DS . $name . '.php';
|
||||
|
||||
if (Configure::read() > 0) {
|
||||
if (Configure::read('debug') > 0) {
|
||||
$expires = "+10 seconds";
|
||||
} else {
|
||||
$expires = "+999 days";
|
||||
|
@ -369,7 +361,7 @@ class Configure extends Object {
|
|||
$prefix = $cache['settings']['prefix'];
|
||||
}
|
||||
|
||||
if (Configure::read() >= 1) {
|
||||
if (Configure::read('debug') >= 1) {
|
||||
$duration = '+10 seconds';
|
||||
} else {
|
||||
$duration = '+999 days';
|
||||
|
|
|
@ -291,7 +291,7 @@ class AuthComponent extends Object {
|
|||
}
|
||||
}
|
||||
$this->_set($settings);
|
||||
if (Configure::read() > 0) {
|
||||
if (Configure::read('debug') > 0) {
|
||||
App::import('Debugger');
|
||||
Debugger::checkSecurityKeys();
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ class AuthComponent extends Object {
|
|||
public function startup(&$controller) {
|
||||
$isErrorOrTests = (
|
||||
strtolower($controller->name) == 'cakeerror' ||
|
||||
(strtolower($controller->name) == 'tests' && Configure::read() > 0)
|
||||
(strtolower($controller->name) == 'tests' && Configure::read('debug') > 0)
|
||||
);
|
||||
if ($isErrorOrTests) {
|
||||
return true;
|
||||
|
|
|
@ -718,7 +718,7 @@ class RequestHandlerComponent extends Object {
|
|||
if (!empty($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->__responseTypeSet = $cType;
|
||||
|
|
|
@ -826,7 +826,7 @@ class Controller extends Object {
|
|||
|
||||
$this->params['models'] = $this->modelNames;
|
||||
|
||||
if (Configure::read() > 2) {
|
||||
if (Configure::read('debug') > 2) {
|
||||
$this->set('cakeDebug', $this);
|
||||
}
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ class Debugger {
|
|||
if (!empty($class)) {
|
||||
if (!$instance || strtolower($class) != strtolower(get_class($instance[0]))) {
|
||||
$instance[0] = & new $class();
|
||||
if (Configure::read() > 0) {
|
||||
if (Configure::read('debug') > 0) {
|
||||
Configure::version(); // Make sure the core config is loaded
|
||||
$instance[0]->helpPath = Configure::read('Cake.Debugger.HelpPath');
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ class Debugger {
|
|||
|
||||
if (!$instance) {
|
||||
$instance[0] =& new Debugger();
|
||||
if (Configure::read() > 0) {
|
||||
if (Configure::read('debug') > 0) {
|
||||
Configure::version(); // Make sure the core config is loaded
|
||||
$instance[0]->helpPath = Configure::read('Cake.Debugger.HelpPath');
|
||||
}
|
||||
|
|
|
@ -977,7 +977,7 @@ class DboOracle extends DboSource {
|
|||
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 (!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) . ' ';
|
||||
if (isset($this->error) && $this->error != null) {
|
||||
echo $this->error;
|
||||
|
|
|
@ -134,7 +134,7 @@ class DboSource extends DataSource {
|
|||
$config['prefix'] = '';
|
||||
}
|
||||
parent::__construct($config);
|
||||
$this->fullDebug = Configure::read() > 1;
|
||||
$this->fullDebug = Configure::read('debug') > 1;
|
||||
if (!$this->enabled()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -651,10 +651,10 @@ class DboSource extends DataSource {
|
|||
*/
|
||||
public function showQuery($sql) {
|
||||
$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) . '[...]';
|
||||
}
|
||||
if (Configure::read() > 0) {
|
||||
if (Configure::read('debug') > 0) {
|
||||
$out = null;
|
||||
if ($error) {
|
||||
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) {
|
||||
if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $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) . ' ';
|
||||
if (isset($this->error) && $this->error != null) {
|
||||
echo $this->error;
|
||||
|
|
|
@ -229,7 +229,7 @@ class Object {
|
|||
$data = str_replace('\\', '\\\\', serialize($objectArray));
|
||||
$data = '<?php $' . $name . ' = \'' . str_replace('\'', '\\\'', $data) . '\' ?>';
|
||||
$duration = '+999 days';
|
||||
if (Configure::read() >= 1) {
|
||||
if (Configure::read('debug') >= 1) {
|
||||
$duration = '+10 seconds';
|
||||
}
|
||||
cache($file, $data, $duration);
|
||||
|
|
|
@ -237,7 +237,7 @@ class Helper extends Object {
|
|||
*/
|
||||
public function assetTimestamp($path) {
|
||||
$timestampEnabled = (
|
||||
(Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
|
||||
(Configure::read('Asset.timestamp') === true && Configure::read('debug') > 0) ||
|
||||
Configure::read('Asset.timestamp') === 'force'
|
||||
);
|
||||
if (strpos($path, '?') === false && $timestampEnabled) {
|
||||
|
|
|
@ -389,7 +389,7 @@ class View extends Object {
|
|||
}
|
||||
$file = $paths[0] . 'elements' . DS . $name . $this->ext;
|
||||
|
||||
if (Configure::read() > 0) {
|
||||
if (Configure::read('debug') > 0) {
|
||||
return "Not Found: " . $file;
|
||||
}
|
||||
}
|
||||
|
@ -524,7 +524,7 @@ class View extends Object {
|
|||
ob_start();
|
||||
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 -->";
|
||||
}
|
||||
$out = ob_get_clean();
|
||||
|
@ -707,7 +707,7 @@ class View extends Object {
|
|||
extract($___dataForView, EXTR_SKIP);
|
||||
ob_start();
|
||||
|
||||
if (Configure::read() > 0) {
|
||||
if (Configure::read('debug') > 0) {
|
||||
include ($___viewFn);
|
||||
} else {
|
||||
@include ($___viewFn);
|
||||
|
|
|
@ -99,6 +99,14 @@ class ConfigureTest extends CakeTestCase {
|
|||
|
||||
$result = Configure::read('debug');
|
||||
$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.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue