mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
adding context and trace to other debugger output formats. adds E_USER_ERROR to fatal
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6242 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
71039959d0
commit
d7926aaaad
4 changed files with 114 additions and 42 deletions
|
@ -407,7 +407,7 @@ div.cake-stack-trace pre, div.cake-code-dump pre {
|
|||
div.cake-code-dump pre, div.cake-code-dump pre code {
|
||||
clear: both;
|
||||
font-size: 12px;
|
||||
line-height: 7px;
|
||||
line-height: 15px;
|
||||
margin: 4px 2px;
|
||||
padding: 4px;
|
||||
overflow: auto;
|
||||
|
|
|
@ -407,7 +407,7 @@ div.cake-stack-trace pre, div.cake-code-dump pre {
|
|||
div.cake-code-dump pre, div.cake-code-dump pre code {
|
||||
clear: both;
|
||||
font-size: 12px;
|
||||
line-height: 7px;
|
||||
line-height: 15px;
|
||||
margin: 4px 2px;
|
||||
padding: 4px;
|
||||
overflow: auto;
|
||||
|
|
|
@ -144,6 +144,7 @@ class Debugger extends Object {
|
|||
case E_ERROR:
|
||||
case E_CORE_ERROR:
|
||||
case E_COMPILE_ERROR:
|
||||
case E_USER_ERROR:
|
||||
$error = 'Fatal Error';
|
||||
$level = LOG_ERROR;
|
||||
break;
|
||||
|
@ -172,7 +173,7 @@ class Debugger extends Object {
|
|||
}
|
||||
}
|
||||
|
||||
echo $_this->__output($level, $error, $code, $description, $file, $line, $context);
|
||||
echo $_this->__output($level, $error, $code, $helpCode, $description, $file, $line, $context);
|
||||
|
||||
if (Configure::read('log')) {
|
||||
CakeLog::write($level, "{$error} ({$code}): {$description} in [{$file}, line {$line}]");
|
||||
|
@ -297,10 +298,11 @@ class Debugger extends Object {
|
|||
if (!isset($data[$i])) {
|
||||
continue;
|
||||
}
|
||||
$string = str_replace(array("\r\n", "\n"), "", highlight_string($data[$i], true));
|
||||
if ($i == $line) {
|
||||
$lines[] = '<span class="code-highlight">' . highlight_string($data[$i], true) . '</span>';
|
||||
$lines[] = '<span class="code-highlight">' . $string . '</span>';
|
||||
} else {
|
||||
$lines[] = highlight_string($data[$i], true);
|
||||
$lines[] = $string;
|
||||
}
|
||||
}
|
||||
return $lines;
|
||||
|
@ -323,21 +325,26 @@ class Debugger extends Object {
|
|||
return $var;
|
||||
break;
|
||||
case 'string':
|
||||
return '"' . $var . '"';
|
||||
return '"' . h($var) . '"';
|
||||
return $echo;
|
||||
break;
|
||||
case 'object':
|
||||
return $_this->__object($var);
|
||||
return get_class($var) . "\n" . $_this->__object($var);
|
||||
case 'array':
|
||||
$out = 'array(';
|
||||
$out = "array(";
|
||||
$vars = array();
|
||||
foreach ($var as $key => $val) {
|
||||
if (is_numeric($key)) {
|
||||
$vars[] = $_this->exportVar($val, $recursion - 1);
|
||||
$vars[] = "\n\t" . $_this->exportVar($val, $recursion - 1);
|
||||
} else {
|
||||
$vars[] = $_this->exportVar($key) . ' => ' . $_this->exportVar($val, $recursion - 1);
|
||||
$vars[] = "\n\t" .$_this->exportVar($key) . ' => ' . $_this->exportVar($val, $recursion - 1);
|
||||
}
|
||||
}
|
||||
return $out . join(",", $vars) . ')';
|
||||
$n = null;
|
||||
if (count($vars) > 0) {
|
||||
$n = "\n";
|
||||
}
|
||||
return $out . join(",", $vars) . "{$n})";
|
||||
break;
|
||||
case 'resource':
|
||||
return strtolower(gettype($var));
|
||||
|
@ -376,7 +383,6 @@ class Debugger extends Object {
|
|||
$value = ife(is_object($value), "*RECURSION* -> " . get_class($value), "*RECURSION*");
|
||||
}
|
||||
}
|
||||
|
||||
if(in_array(gettype($value), array('boolean', 'integer', 'double', 'string', 'array', 'resource', 'object', 'null'))) {
|
||||
$out[] = "$className::$$key = " . Debugger::exportVar($value);
|
||||
} else {
|
||||
|
@ -419,60 +425,70 @@ class Debugger extends Object {
|
|||
* @param string $var Object to convert
|
||||
* @access private
|
||||
*/
|
||||
function __output($level, $error, $code, $description, $file, $line, $context) {
|
||||
function __output($level, $error, $code, $helpCode, $description, $file, $line, $kontext) {
|
||||
$_this = Debugger::getInstance();
|
||||
|
||||
$files = $_this->trace(array('start' => 2, 'format' => 'points'));
|
||||
$listing = $_this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1);
|
||||
$trace = $_this->trace(array('start' => 2));
|
||||
$context = array();
|
||||
|
||||
foreach ((array)$kontext as $var => $value) {
|
||||
$context[] = "\${$var}\t=\t" . $_this->exportVar($value, 1);
|
||||
}
|
||||
|
||||
switch ($_this->__outputFormat) {
|
||||
default:
|
||||
case 'js':
|
||||
$link = "document.getElementById(\"CakeStackTrace" . count($_this->errors) . "\").style.display = (document.getElementById(\"CakeStackTrace" . count($_this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
|
||||
$out = "<a href='javascript:void(0);' onclick='{$link}'><b>{$error}</b> ({$code})</a>: {$description} [<b>{$file}</b>, line <b>{$line}</b>]";
|
||||
|
||||
if (Configure::read() > 0) {
|
||||
debug($out, false, false);
|
||||
e('<div id="CakeStackTrace' . count($_this->errors) . '" class="cake-stack-trace" style="display: none;">');
|
||||
if (!empty($context)) {
|
||||
$link = "document.getElementById(\"CakeErrorContext" . count($_this->errors) . "\").style.display = (document.getElementById(\"CakeErrorContext" . count($_this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
|
||||
e("<a href='javascript:void(0);' onclick='{$link}'>Context</a> | ");
|
||||
$link = "document.getElementById(\"CakeErrorCode" . count($_this->errors) . "\").style.display = (document.getElementById(\"CakeErrorCode" . count($_this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
|
||||
e("<a href='javascript:void(0);' onclick='{$link}'>Code</a>");
|
||||
|
||||
if (!empty($helpCode)) {
|
||||
e(" | <a href='{$_this->helpPath}{$helpCode}' target='blank'>Help</a>");
|
||||
if (!empty($context)) {
|
||||
$link = "document.getElementById(\"CakeErrorContext" . count($_this->errors) . "\").style.display = (document.getElementById(\"CakeErrorContext" . count($_this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
|
||||
e(" | <a href='javascript:void(0);' onclick='{$link}'>Context</a>");
|
||||
|
||||
if (!empty($helpCode)) {
|
||||
e(" | <a href='{$_this->helpPath}{$helpCode}' target='blank'>Help</a>");
|
||||
}
|
||||
|
||||
e("<pre id=\"CakeErrorContext" . count($_this->errors) . "\" class=\"cake-context\" style=\"display: none;\">");
|
||||
e(implode("\n", $context));
|
||||
e("</pre>");
|
||||
}
|
||||
|
||||
e("<pre id=\"CakeErrorContext" . count($_this->errors) . "\" class=\"cake-context\" style=\"display: none;\">");
|
||||
foreach ($context as $var => $value) {
|
||||
e("\${$var}\t=\t" . $_this->exportVar($value, 1) . "\n");
|
||||
}
|
||||
e("</pre>");
|
||||
}
|
||||
}
|
||||
|
||||
$files = $_this->trace(array('start' => 1, 'format' => 'points'));
|
||||
$listing = Debugger::excerpt($files[0]['file'], $files[0]['line'] - 1, 2);
|
||||
|
||||
if (Configure::read() > 0) {
|
||||
e("<div id=\"CakeErrorCode" . count($_this->errors) . "\" class=\"cake-code-dump\" style=\"display: none;\">");
|
||||
pr(implode("\n", $listing), false);
|
||||
e('</div>');
|
||||
|
||||
pr($_this->trace(array('start' => 1)), false);
|
||||
e("<div id=\"CakeErrorCode" . count($_this->errors) . "\" class=\"cake-code-dump\" style=\"display: none;\">");
|
||||
pr(implode("\n", $listing) . "\n", false);
|
||||
e('</div>');
|
||||
pr($trace, false);
|
||||
e('</div>');
|
||||
}
|
||||
break;
|
||||
case 'html':
|
||||
echo "<pre class=\"cake-debug\"><b>{$error}</b> ({$code}) : {$description} [<b>{$file}</b>, line <b>{$line}]</b></pre>";
|
||||
if (!empty($context)) {
|
||||
echo "Context:\n" .implode("\n", $context) . "\n";
|
||||
}
|
||||
echo "<pre class=\"cake-debug context\"><b>Context</b> <p>" . implode("\n", $context) . "</p></pre>";
|
||||
echo "<pre class=\"cake-debug trace\"><b>Trace</b> <p>" . $trace. "</p></pre>";
|
||||
break;
|
||||
case 'text':
|
||||
case 'txt':
|
||||
echo "{$error}: {$code} :: {$description} on line {$line} of {$file}\n";
|
||||
if (!empty($context)) {
|
||||
echo "Context:\n" .implode("\n", $context) . "\n";
|
||||
}
|
||||
echo "Trace:\n" . $trace;
|
||||
break;
|
||||
case 'log':
|
||||
$_this->log(compact('error', 'code', 'description', 'line', 'file'));
|
||||
$_this->log(compact('error', 'code', 'description', 'line', 'file', 'context', 'trace'));
|
||||
break;
|
||||
case false:
|
||||
$this->__data[] = compact('error', 'code', 'description', 'line', 'file');
|
||||
$this->__data[] = compact('error', 'code', 'description', 'line', 'file', 'context', 'trace');
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,14 +43,70 @@ class DebuggerTest extends UnitTestCase {
|
|||
$this->assertEqual($result, '');
|
||||
$out .= '';
|
||||
$result = Debugger::output(true);
|
||||
$expected = array(array('error' => 'Notice', 'code' => '8', 'description' => 'Undefined variable: out', 'line' => '44', 'file' => 'CORE/cake/tests/cases/libs/debugger.test.php'));
|
||||
$expected = array(array(
|
||||
'error' => 'Notice', 'code' => '8', 'description' => 'Undefined variable: out', 'line' => '44', 'file' => 'CORE/cake/tests/cases/libs/debugger.test.php',
|
||||
'context' => array("\$result\t=\tnull"),
|
||||
'trace' => "DebuggerTest::testOutput() - CORE/cake/tests/cases/libs/debugger.test.php, line 44
|
||||
SimpleInvoker::invoke() - CORE/vendors/simpletest/invoker.php, line 68
|
||||
SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126
|
||||
SimpleErrorTrappingInvoker::invoke() - CORE/vendors/simpletest/errors.php, line 48
|
||||
SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126
|
||||
SimpleExceptionTrappingInvoker::invoke() - CORE/vendors/simpletest/exceptions.php, line 42
|
||||
SimpleTestCase::run() - CORE/vendors/simpletest/test_case.php, line 135
|
||||
TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 588
|
||||
TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 591
|
||||
TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93
|
||||
[main] - CORE/app/webroot/test.php, line 240"
|
||||
)
|
||||
);
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", $result);
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
ob_start();
|
||||
Debugger::output('txt');
|
||||
$other .= '';
|
||||
$result = ob_get_clean();
|
||||
$expected = "Notice: 8 :: Undefined variable: other on line 51 of CORE/cake/tests/cases/libs/debugger.test.php\n";
|
||||
$expected = "Notice: 8 :: Undefined variable: other on line 67 of CORE/cake/tests/cases/libs/debugger.test.php\n";
|
||||
$expected .= 'Context:
|
||||
$result = array(array("error" => "Notice","code" => 8,"description" => "Undefined variable: out","line" => 44,"file" => "CORE/cake/tests/cases/libs/debugger.test.php","context" => array("$result = null"),"trace" => "DebuggerTest::testOutput() - CORE/cake/tests/cases/libs/debugger.test.php, line 44
|
||||
SimpleInvoker::invoke() - CORE/vendors/simpletest/invoker.php, line 68
|
||||
SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126
|
||||
SimpleErrorTrappingInvoker::invoke() - CORE/vendors/simpletest/errors.php, line 48
|
||||
SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126
|
||||
SimpleExceptionTrappingInvoker::invoke() - CORE/vendors/simpletest/exceptions.php, line 42
|
||||
SimpleTestCase::run() - CORE/vendors/simpletest/test_case.php, line 135
|
||||
TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 588
|
||||
TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 591
|
||||
TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93
|
||||
[main] - CORE/app/webroot/test.php, line 240"))
|
||||
$out = ""
|
||||
$expected = array(array("error" => "Notice","code" => "8","description" => "Undefined variable: out","line" => "44","file" => "CORE/cake/tests/cases/libs/debugger.test.php","context" => array("$result = null"),"trace" => "DebuggerTest::testOutput() - CORE/cake/tests/cases/libs/debugger.test.php, line 44
|
||||
SimpleInvoker::invoke() - CORE/vendors/simpletest/invoker.php, line 68
|
||||
SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126
|
||||
SimpleErrorTrappingInvoker::invoke() - CORE/vendors/simpletest/errors.php, line 48
|
||||
SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126
|
||||
SimpleExceptionTrappingInvoker::invoke() - CORE/vendors/simpletest/exceptions.php, line 42
|
||||
SimpleTestCase::run() - CORE/vendors/simpletest/test_case.php, line 135
|
||||
TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 588
|
||||
TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 591
|
||||
TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93
|
||||
[main] - CORE/app/webroot/test.php, line 240"))
|
||||
';
|
||||
$expected .= 'Trace:
|
||||
DebuggerTest::testOutput() - CORE/cake/tests/cases/libs/debugger.test.php, line 67
|
||||
SimpleInvoker::invoke() - CORE/vendors/simpletest/invoker.php, line 68
|
||||
SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126
|
||||
SimpleErrorTrappingInvoker::invoke() - CORE/vendors/simpletest/errors.php, line 48
|
||||
SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126
|
||||
SimpleExceptionTrappingInvoker::invoke() - CORE/vendors/simpletest/exceptions.php, line 42
|
||||
SimpleTestCase::run() - CORE/vendors/simpletest/test_case.php, line 135
|
||||
TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 588
|
||||
TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 591
|
||||
TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93
|
||||
[main] - CORE/app/webroot/test.php, line 240';
|
||||
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", $result);
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
|
@ -63,7 +119,7 @@ class DebuggerTest extends UnitTestCase {
|
|||
$Controller->helpers = array('Html', 'Form');
|
||||
$View = new View($Controller);
|
||||
$result = Debugger::exportVar($View);
|
||||
$expected = 'View::$base = "[empty string]"
|
||||
$expected = 'ViewView::$base = "[empty string]"
|
||||
View::$here = "[empty string]"
|
||||
View::$plugin = "[empty string]"
|
||||
View::$name = "[empty string]"
|
||||
|
|
Loading…
Reference in a new issue