mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Unwinding several ifs used in debug(). Creating simple string templates instead. Fixes #818
This commit is contained in:
parent
cef9927604
commit
02ade65509
2 changed files with 25 additions and 19 deletions
|
@ -92,33 +92,39 @@
|
||||||
*/
|
*/
|
||||||
function debug($var = false, $showHtml = false, $showFrom = true) {
|
function debug($var = false, $showHtml = false, $showFrom = true) {
|
||||||
if (Configure::read('debug') > 0) {
|
if (Configure::read('debug') > 0) {
|
||||||
|
$file = '';
|
||||||
|
$line = '';
|
||||||
if ($showFrom) {
|
if ($showFrom) {
|
||||||
$calledFrom = debug_backtrace();
|
$calledFrom = debug_backtrace();
|
||||||
if(defined('CAKEPHP_SHELL')){
|
$file = substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1);
|
||||||
echo "##########DEBUG##########\n";
|
$line = $calledFrom[0]['line'];
|
||||||
echo substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) ;
|
|
||||||
echo ' (line ' . $calledFrom[0]['line'] . ')'."\n";
|
|
||||||
}else{
|
|
||||||
echo '<strong>' . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . '</strong>';
|
|
||||||
echo ' (line <strong>' . $calledFrom[0]['line'] . '</strong>)';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!defined('CAKEPHP_SHELL')){
|
|
||||||
echo "\n<pre class=\"cake-debug\">\n";
|
|
||||||
}
|
}
|
||||||
|
$html = <<<HTML
|
||||||
|
<strong>%s</strong> (line <strong>%s</strong>)
|
||||||
|
<pre class="cake-debug">
|
||||||
|
%s
|
||||||
|
</pre>
|
||||||
|
HTML;
|
||||||
|
$text = <<<TEXT
|
||||||
|
|
||||||
|
%s (line %s)
|
||||||
|
########## DEBUG ##########
|
||||||
|
%s
|
||||||
|
###########################
|
||||||
|
|
||||||
|
TEXT;
|
||||||
|
$template = $html;
|
||||||
|
if (php_sapi_name() == 'cli') {
|
||||||
|
$template = $text;
|
||||||
|
}
|
||||||
$var = print_r($var, true);
|
$var = print_r($var, true);
|
||||||
if ($showHtml) {
|
if ($showHtml) {
|
||||||
$var = str_replace('<', '<', str_replace('>', '>', $var));
|
$var = str_replace('<', '<', str_replace('>', '>', $var));
|
||||||
}
|
}
|
||||||
echo $var . "\n";
|
printf($template, $file, $line, $var);
|
||||||
if(!defined('CAKEPHP_SHELL')){
|
|
||||||
echo "<pre class=\"cake-debug\">\n";
|
|
||||||
}else{
|
|
||||||
echo "#########################\n";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('sortByKey')) {
|
if (!function_exists('sortByKey')) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -585,7 +585,7 @@ class BasicsTest extends CakeTestCase {
|
||||||
ob_start();
|
ob_start();
|
||||||
debug('this-is-a-test');
|
debug('this-is-a-test');
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
$pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
|
$pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
|
||||||
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
|
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
|
||||||
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*this-is-a-test.*/s';
|
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*this-is-a-test.*/s';
|
||||||
$this->assertPattern($pattern, $result);
|
$this->assertPattern($pattern, $result);
|
||||||
|
@ -593,7 +593,7 @@ class BasicsTest extends CakeTestCase {
|
||||||
ob_start();
|
ob_start();
|
||||||
debug('<div>this-is-a-test</div>', true);
|
debug('<div>this-is-a-test</div>', true);
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
$pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
|
$pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
|
||||||
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
|
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
|
||||||
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*<div>this-is-a-test<\/div>.*/s';
|
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*<div>this-is-a-test<\/div>.*/s';
|
||||||
$this->assertPattern($pattern, $result);
|
$this->assertPattern($pattern, $result);
|
||||||
|
|
Loading…
Reference in a new issue