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) {
|
||||
if (Configure::read('debug') > 0) {
|
||||
$file = '';
|
||||
$line = '';
|
||||
if ($showFrom) {
|
||||
$calledFrom = debug_backtrace();
|
||||
if(defined('CAKEPHP_SHELL')){
|
||||
echo "##########DEBUG##########\n";
|
||||
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";
|
||||
$file = substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1);
|
||||
$line = $calledFrom[0]['line'];
|
||||
}
|
||||
$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);
|
||||
if ($showHtml) {
|
||||
$var = str_replace('<', '<', str_replace('>', '>', $var));
|
||||
}
|
||||
echo $var . "\n";
|
||||
if(!defined('CAKEPHP_SHELL')){
|
||||
echo "<pre class=\"cake-debug\">\n";
|
||||
}else{
|
||||
echo "#########################\n";
|
||||
};
|
||||
printf($template, $file, $line, $var);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('sortByKey')) {
|
||||
|
||||
/**
|
||||
|
|
|
@ -585,7 +585,7 @@ class BasicsTest extends CakeTestCase {
|
|||
ob_start();
|
||||
debug('this-is-a-test');
|
||||
$result = ob_get_clean();
|
||||
$pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
|
||||
$pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
|
||||
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
|
||||
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*this-is-a-test.*/s';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
@ -593,7 +593,7 @@ class BasicsTest extends CakeTestCase {
|
|||
ob_start();
|
||||
debug('<div>this-is-a-test</div>', true);
|
||||
$result = ob_get_clean();
|
||||
$pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
|
||||
$pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
|
||||
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
|
||||
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*<div>this-is-a-test<\/div>.*/s';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
|
Loading…
Reference in a new issue