Пример #1
0
 /**
  * @param bool|false $flag
  * @return $this
  */
 public function setDebugEnabled($flag = false)
 {
     if (!$this->_debugger) {
         //只有在debug开启时才实例化debugger,并且不能置于构造方法中,否则形成死循环
         $this->_debugger = Debugger::getInstance();
     }
     $this->_debugger->setEnabled($flag);
     return $this;
 }
 /**
  * test output switch to firePHP
  *
  * @return void
  */
 public function testOutput()
 {
     Debugger::getInstance('DebugKitDebugger');
     Debugger::addFormat('fb', array('callback' => 'DebugKitDebugger::fireError'));
     Debugger::outputAs('fb');
     set_error_handler('ErrorHandler::handleError');
     $foo .= '';
     restore_error_handler();
     $result = $this->firecake->sentHeaders;
     $this->assertRegExp('/GROUP_START/', $result['X-Wf-1-1-1-1']);
     $this->assertRegExp('/ERROR/', $result['X-Wf-1-1-1-2']);
     $this->assertRegExp('/GROUP_END/', $result['X-Wf-1-1-1-5']);
     Debugger::getInstance('Debugger');
     Debugger::outputAs('html');
 }
Пример #3
0
 function __debug()
 {
     $argc = func_num_args();
     $args = func_get_args();
     if ($argc == 0) {
         return false;
     }
     global $__session;
     if (Configure::read() == 0) {
         return false;
     }
     $class = 'CakeSession';
     if ($__session === null) {
         if (ClassRegistry::isKeySet($class)) {
             $__session =& ClassRegistry::getObject($class);
         } else {
             if (!class_exists($class)) {
                 App::import('Core', $class);
             }
             $__session =& new $class();
             ClassRegistry::addObject($class, $__session);
         }
     }
     $session =& $__session;
     if (!$session->started()) {
         $session->start();
     }
     $debugs = array();
     if ($session->check('debug.printable')) {
         $debugs = $session->read('debug.printable');
     }
     $debugger =& Debugger::getInstance();
     $trace = $debugger->trace(aa('start', 2, 'format', 'array'));
     while ($trace[0]['function'] === __FUNCTION__ || false !== strpos($trace[0]['function'], 'call_user_func')) {
         array_shift($trace);
     }
     $debug = compact('args', 'trace');
     $debugs = array_merge($debugs, array($debug));
     // debug(compact('prints','args'));
     $session->write('debug.printable', $debugs);
     return true;
 }
Пример #4
0
 private function _output($sql, $params = array())
 {
     $unqid = uniqid();
     Debugger::getInstance()->timerStart($unqid);
     $conn = Database::getConnection();
     if ($params) {
         $query = $conn->prepare($sql);
         $query->execute($params);
         $sqlForDebugger = $sql . '  (' . implode(',', $params) . ')';
     } else {
         $query = $conn->query($sql);
         $sqlForDebugger = $sql;
     }
     if (!$query) {
         return false;
     }
     $return = $query->fetchAll(PDO::FETCH_ASSOC);
     Debugger::getInstance()->addSql(array($sqlForDebugger, $query->rowCount(), Debugger::getInstance()->timerEnd($unqid, false)));
     return $return;
 }
Пример #5
0
 /**
  * override core one with the following enhancements/fixes:
  * - 404s log to a different domain
  * - IP, Referer and Browser-Infos are added for better error debugging/tracing
  * 2011-12-21 ms
  */
 public static function handleError($code, $description, $file = null, $line = null, $context = null)
 {
     if (error_reporting() === 0) {
         return false;
     }
     $errorConfig = Configure::read('Error');
     list($error, $log) = self::mapErrorCode($code);
     $debug = Configure::read('debug');
     if ($debug) {
         $data = array('level' => $log, 'code' => $code, 'error' => $error, 'description' => $description, 'file' => $file, 'line' => $line, 'context' => $context, 'start' => 2, 'path' => Debugger::trimPath($file));
         return Debugger::getInstance()->outputError($data);
     } else {
         $message = $error . ' (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
         if (!empty($errorConfig['trace'])) {
             $trace = Debugger::trace(array('start' => 1, 'format' => 'log'));
             $message .= "\nTrace:\n" . $trace . "\n";
             $message .= self::traceDetails();
         }
         return CakeLog::write($log, $message);
     }
 }
Пример #6
0
 /**
  * testOutput method
  *
  * @access public
  * @return void
  */
 function testOutput()
 {
     Debugger::invoke(Debugger::getInstance());
     $result = Debugger::output(false);
     $this->assertEqual($result, '');
     $out .= '';
     $result = Debugger::output(true);
     $this->assertEqual($result[0]['error'], 'Notice');
     $this->assertEqual($result[0]['description'], 'Undefined variable: out');
     $this->assertPattern('/DebuggerTest::testOutput/', $result[0]['trace']);
     $this->assertPattern('/SimpleInvoker::invoke/', $result[0]['trace']);
     ob_start();
     Debugger::output('txt');
     $other .= '';
     $result = ob_get_clean();
     $this->assertPattern('/Undefined variable: other/', $result);
     $this->assertPattern('/Context:/', $result);
     $this->assertPattern('/DebuggerTest::testOutput/', $result);
     $this->assertPattern('/SimpleInvoker::invoke/', $result);
     ob_start();
     Debugger::output('html');
     $wrong .= '';
     $result = ob_get_clean();
     $this->assertPattern('/<pre class="cake-debug">.+<\\/pre>/', $result);
     $this->assertPattern('/<b>Notice<\\/b>/', $result);
     $this->assertPattern('/variable: wrong/', $result);
     ob_start();
     Debugger::output('js');
     $buzz .= '';
     $result = ob_get_clean();
     $this->assertPattern("/<a href\\='javascript:void\\(0\\);' onclick\\='/", $result);
     $this->assertPattern('/<b>Notice<\\/b>/', $result);
     $this->assertPattern('/Undefined variable: buzz/', $result);
     $this->assertPattern('/<a[^>]+>Code<\\/a>/', $result);
     $this->assertPattern('/<a[^>]+>Context<\\/a>/', $result);
     set_error_handler('simpleTestErrorHandler');
 }
Пример #7
0
 /**
  * test getInstance.
  *
  * @access public
  * @return void
  */
 function testGetInstance()
 {
     $result = Debugger::getInstance();
     $this->assertIsA($result, 'Debugger');
     $result = Debugger::getInstance('DebuggerTestCaseDebugger');
     $this->assertIsA($result, 'DebuggerTestCaseDebugger');
     $result = Debugger::getInstance();
     $this->assertIsA($result, 'DebuggerTestCaseDebugger');
     $result = Debugger::getInstance('Debugger');
     $this->assertIsA($result, 'Debugger');
 }
Пример #8
0
 private function initDebugger()
 {
     $this->debug = Debugger::getInstance($this->config->get('config.debugger'));
 }
Пример #9
0
define('ROOT', __DIR__ . '/');
define('ROOT_URL', 'http://' . $_SERVER['HTTP_HOST'] . str_replace('index.php', '', $_SERVER['PHP_SELF']));
define('CONTROLLER_DIR', ROOT . '_app/controller/');
define('MODEL_DIR', ROOT . '_app/model/');
define('LIBS_DIR', ROOT . '_app/libs/');
define('VIEW_DIR', ROOT . '_app/view/');
function autoLoad($className)
{
    if (file_exists(CONTROLLER_DIR . $className . '.class.php')) {
        require CONTROLLER_DIR . $className . '.class.php';
    } else {
        if (file_exists(MODEL_DIR . $className . '.class.php')) {
            require MODEL_DIR . $className . '.class.php';
        } else {
            if (file_exists(LIBS_DIR . $className . '.class.php')) {
                require LIBS_DIR . $className . '.class.php';
            }
        }
    }
}
spl_autoload_register('autoLoad');
$dbg = Debugger::getInstance();
Database::connect("localhost", "root", "", "logger");
//Database::connect("217.16.184.116", "logger", "2A?cc9w3", "logger_db");
$router = new Router($_SERVER['REQUEST_URI'], 'dashboard');
$dbg->dump(array_diff(get_declared_classes(), $predefinedClasses), 'All user defined classes');
$dbg->dump($router, 'Router');
$dbg->dump($_SESSION, 'SESSION');
if (filter_input(INPUT_GET, "debug") == 1) {
    $dbg->printAll();
}
Пример #10
0
 /**
  * Handles object conversion to debug string.
  *
  * @param string $var Object to convert
  * @access protected
  */
 function output($format = 'js')
 {
     $_this = Debugger::getInstance();
     $data = null;
     if ($format === true && !empty($_this->__data)) {
         $data = $_this->__data;
         $_this->__data = array();
         $format = false;
     }
     $_this->_outputFormat = $format;
     return $data;
 }
Пример #11
0
 /**
  * Switches output format, updates format strings
  *
  * @param string $format Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for
  *    straight HTML output, or 'txt' for unformatted text.
  * @param array $strings Template strings to be used for the output format.
  * @access protected
  */
 function output($format = null, $strings = array())
 {
     $_this =& Debugger::getInstance();
     $data = null;
     if (is_null($format)) {
         return $_this->_outputFormat;
     }
     if (!empty($strings)) {
         if (isset($_this->_templates[$format])) {
             if (isset($strings['links'])) {
                 $_this->_templates[$format]['links'] = array_merge($_this->_templates[$format]['links'], $strings['links']);
                 unset($strings['links']);
             }
             $_this->_templates[$format] = array_merge($_this->_templates[$format], $strings);
         } else {
             $_this->_templates[$format] = $strings;
         }
         return $_this->_templates[$format];
     }
     if ($format === true && !empty($_this->_data)) {
         $data = $_this->_data;
         $_this->_data = array();
         $format = false;
     }
     $_this->_outputFormat = $format;
     return $data;
 }
Пример #12
0
 protected function getDebugger()
 {
     return Debugger::getInstance();
 }
Пример #13
0
<div id="megaBlock">
	
		<div id="header">
			<?php 
echo View::factory('element/logo');
?>
		</div>
			
		<div id="main">
			<?php 
echo $content;
?>
		</div>
		<div class="footerPush"></div>
	</div>
 
	<div id="footer">
	</div>
	
	
<?php 
$render = Debugger::getInstance()->render();
if ($render) {
    echo '<div class="debug-panel">';
    echo $render;
    echo '</div>';
}
?>
 
</body>
</html>		
Пример #14
0
 /**
  * Set as the default error handler by CakePHP. Use Configure::write('Error.handler', $callback), to use your own
  * error handling methods. This function will use Debugger to display errors when debug > 0. And
  * will log errors to CakeLog, when debug == 0.
  *
  * You can use Configure::write('Error.level', $value); to set what type of errors will be handled here.
  * Stack traces for errors can be enabled with Configure::write('Error.trace', true);
  *
  * @param int $code Code of error
  * @param string $description Error description
  * @param string $file File on which error occurred
  * @param int $line Line that triggered the error
  * @param array $context Context
  * @return bool true if error was handled
  */
 public static function handleError($code, $description, $file = null, $line = null, $context = null)
 {
     if (error_reporting() === 0) {
         return false;
     }
     $errorConfig = Configure::read('Error');
     list($error, $log) = self::mapErrorCode($code);
     if ($log === LOG_ERR) {
         return self::handleFatalError($code, $description, $file, $line);
     }
     $debug = Configure::read('debug');
     if ($debug) {
         $data = array('level' => $log, 'code' => $code, 'error' => $error, 'description' => $description, 'file' => $file, 'line' => $line, 'context' => $context, 'start' => 2, 'path' => Debugger::trimPath($file));
         return Debugger::getInstance()->outputError($data);
     }
     $message = $error . ' (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
     #mod blamoo@live.com
     $message .= "\nForwarded-For: " . (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : '(None)');
     #MOD
     $message .= "\nReferer: " . (isset($_SERVER['HTTP_REFERER']) ? "<a href=\"{$_SERVER['HTTP_REFERER']}\">{$_SERVER['HTTP_REFERER']}</a>" : '(None)');
     #MOD
     $message .= "\nUA: " . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '(None)');
     #MOD
     $message .= "\nMethod: " . (isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '(None)');
     #MOD
     if (count($_POST) !== 0) {
         $message .= "\nPost: <pre>" . var_export($_POST, true) . '</pre>';
         #MOD
     }
     #endmod
     if (!empty($errorConfig['trace'])) {
         $trace = Debugger::trace(array('start' => 1, 'format' => 'log'));
         $message .= "\nTrace:\n" . $trace . "\n";
     }
     return CakeLog::write($log, $message);
 }
Пример #15
0
    function testOutput()
    {
        if (file_exists(APP . DS . 'vendors' . DS . 'simpletest' . DS . 'reporter.php')) {
            define('SIMPLETESTVENDORPATH', 'APP' . DS . 'vendors');
        } else {
            define('SIMPLETESTVENDORPATH', 'CORE' . DS . 'vendors');
        }
        Debugger::invoke(Debugger::getInstance());
        $result = Debugger::output(false);
        $this->assertEqual($result, '');
        $out .= '';
        $result = Debugger::output(true);
        $expected = array(array('error' => 'Notice', 'code' => '8', 'description' => 'Undefined variable: out', 'line' => '48', '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 48\nSimpleInvoker::invoke() - " . SIMPLETESTVENDORPATH . "/simpletest/invoker.php, line 68\nSimpleInvokerDecorator::invoke() - " . SIMPLETESTVENDORPATH . "/simpletest/invoker.php, line 126\nSimpleErrorTrappingInvoker::invoke() - " . SIMPLETESTVENDORPATH . "/simpletest/errors.php, line 48\nSimpleInvokerDecorator::invoke() - " . SIMPLETESTVENDORPATH . "/simpletest/invoker.php, line 126\nSimpleExceptionTrappingInvoker::invoke() - " . SIMPLETESTVENDORPATH . "/simpletest/exceptions.php, line 42\nSimpleTestCase::run() - " . SIMPLETESTVENDORPATH . "/simpletest/test_case.php, line 135\nTestSuite::run() - " . SIMPLETESTVENDORPATH . "/simpletest/test_case.php, line 588\nTestSuite::run() - " . SIMPLETESTVENDORPATH . "/simpletest/test_case.php, line 591\nTestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93\n[main] - 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 71 of CORE/cake/tests/cases/libs/debugger.test.php\n";
        $expected .= 'Context:
$result	=	array(array("error" => "Notice","code" => 8,"description" => "Undefined variable: out","line" => 48,"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 48
SimpleInvoker::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/invoker.php, line 68
SimpleInvokerDecorator::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/invoker.php, line 126
SimpleErrorTrappingInvoker::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/errors.php, line 48
SimpleInvokerDecorator::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/invoker.php, line 126
SimpleExceptionTrappingInvoker::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/exceptions.php, line 42
SimpleTestCase::run() - ' . SIMPLETESTVENDORPATH . '/simpletest/test_case.php, line 135
TestSuite::run() - ' . SIMPLETESTVENDORPATH . '/simpletest/test_case.php, line 588
TestSuite::run() - ' . SIMPLETESTVENDORPATH . '/simpletest/test_case.php, line 591
TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93
[main] - APP/webroot/test.php, line 240"))
$out	=	"[empty string]"
$expected	=	array(array("error" => "Notice","code" => "8","description" => "Undefined variable: out","line" => "48","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 48
SimpleInvoker::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/invoker.php, line 68
SimpleInvokerDecorator::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/invoker.php, line 126
SimpleErrorTrappingInvoker::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/errors.php, line 48
SimpleInvokerDecorator::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/invoker.php, line 126
SimpleExceptionTrappingInvoker::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/exceptions.php, line 42
SimpleTestCase::run() - ' . SIMPLETESTVENDORPATH . '/simpletest/test_case.php, line 135
TestSuite::run() - ' . SIMPLETESTVENDORPATH . '/simpletest/test_case.php, line 588
TestSuite::run() - ' . SIMPLETESTVENDORPATH . '/simpletest/test_case.php, line 591
TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93
[main] - APP/webroot/test.php, line 240"))
';
        $expected .= 'Trace:
DebuggerTest::testOutput() - CORE/cake/tests/cases/libs/debugger.test.php, line 71
SimpleInvoker::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/invoker.php, line 68
SimpleInvokerDecorator::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/invoker.php, line 126
SimpleErrorTrappingInvoker::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/errors.php, line 48
SimpleInvokerDecorator::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/invoker.php, line 126
SimpleExceptionTrappingInvoker::invoke() - ' . SIMPLETESTVENDORPATH . '/simpletest/exceptions.php, line 42
SimpleTestCase::run() - ' . SIMPLETESTVENDORPATH . '/simpletest/test_case.php, line 135
TestSuite::run() - ' . SIMPLETESTVENDORPATH . '/simpletest/test_case.php, line 588
TestSuite::run() - ' . SIMPLETESTVENDORPATH . '/simpletest/test_case.php, line 591
TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93
[main] - 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');
    }
Пример #16
0
 /**
  * Handles object conversion to debug string
  *
  * @param string $var Object to convert
  * @access private
  */
 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, 'depth' => '20'));
     $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;">');
                 $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($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("<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', 'context', 'trace'));
             break;
         case false:
             $this->__data[] = compact('error', 'code', 'description', 'line', 'file', 'context', 'trace');
             break;
     }
 }
/**
 * test output switch to firePHP
 *
 * @return void
 */
	public function testOutput() {

		$firecake = FireCake::getInstance('TestFireCake');
		Debugger::getInstance('DebugKitDebugger');
		Debugger::output('fb');

		set_error_handler('ErrorHandler::handleError');
		$foo .= '';
		restore_error_handler();

		$result = $firecake->sentHeaders;

		$this->assertPattern('/GROUP_START/', $result['X-Wf-1-1-1-1']);
		$this->assertPattern('/ERROR/', $result['X-Wf-1-1-1-2']);
		$this->assertPattern('/GROUP_END/', $result['X-Wf-1-1-1-5']);

		Debugger::getInstance('Debugger');
		Debugger::output();
	}
Пример #18
0
 /**
  * test error mappings
  *
  * @dataProvider errorProvider
  * @return void
  */
 public function testErrorMapping($error, $expected)
 {
     set_error_handler('ErrorHandler::handleError');
     $this->_restoreError = true;
     Debugger::getInstance()->output('html');
     ob_start();
     trigger_error('Test error', $error);
     $result = ob_get_clean();
     $this->assertRegExp('/<b>' . $expected . '<\\/b>/', $result);
 }
Пример #19
0
 /**
  * Switches output format, updates format strings.
  * Can be used to switch the active output format:
  *
  * @param string $format Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for
  *    straight HTML output, or 'txt' for unformatted text.
  * @param array $strings Template strings to be used for the output format.
  * @return string
  * @deprecated Use Debugger::outputAs() and Debugger::addFormat(). Will be removed
  *   in 3.0
  */
 public function output($format = null, $strings = array())
 {
     $self = Debugger::getInstance();
     $data = null;
     if ($format === null) {
         return Debugger::outputAs();
     }
     if (!empty($strings)) {
         return Debugger::addFormat($format, $strings);
     }
     if ($format === true && !empty($self->_data)) {
         $data = $self->_data;
         $self->_data = array();
         $format = false;
     }
     Debugger::outputAs($format);
     return $data;
 }
Пример #20
0
 /**
  * test _output switch to firePHP
  *
  * @return void
  */
 function testOutput()
 {
     $firecake =& FireCake::getInstance('TestFireCake');
     Debugger::invoke(DebugKitDebugger::getInstance('DebugKitDebugger'));
     Debugger::output('fb');
     $foo .= '';
     $result = $firecake->sentHeaders;
     $this->assertPattern('/GROUP_START/', $result['X-Wf-1-1-1-1']);
     $this->assertPattern('/ERROR/', $result['X-Wf-1-1-1-2']);
     $this->assertPattern('/GROUP_END/', $result['X-Wf-1-1-1-5']);
     Debugger::invoke(Debugger::getInstance('Debugger'));
     Debugger::output();
 }
        } else {
            echo parent::_output($level, $error, $code, $helpCode, $description, $file, $line, $kontext);
        }
    }
    /**
     * Create a FirePHP error message
     *
     * @param string $error Name of error
     * @param string $code  Code of error
     * @param string $description Description of error
     * @param string $file File error occured in
     * @param string $line Line error occured on
     * @param string $trace Stack trace at time of error
     * @param string $context context of error
     * @return void
     * @access protected
     */
    function _fireError($error, $code, $description, $file, $line, $trace, $context)
    {
        $name = $error . ' - ' . $description;
        $message = "{$error} {$code} {$description} on line: {$line} in file: {$file}";
        FireCake::group($name);
        FireCake::error($message, $name);
        FireCake::log($context, 'Context');
        FireCake::log($trace, 'Trace');
        FireCake::groupEnd();
    }
}
Debugger::invoke(DebugKitDebugger::getInstance());
Debugger::getInstance('DebugKitDebugger');
 /**
  * test getInstance.
  *
  * @return void
  */
 public function testGetInstance()
 {
     $result = Debugger::getInstance();
     $this->assertInstanceOf('Debugger', $result);
     $result = Debugger::getInstance('DebuggerTestCaseDebugger');
     $this->assertInstanceOf('DebuggerTestCaseDebugger', $result);
     $result = Debugger::getInstance();
     $this->assertInstanceOf('DebuggerTestCaseDebugger', $result);
     $result = Debugger::getInstance('Debugger');
     $this->assertInstanceOf('Debugger', $result);
 }
Пример #23
0
 /**
  * Set as the default error handler by CakePHP. Use Configure::write('Error.handler', $callback), to use your own
  * error handling methods. This function will use Debugger to display errors when debug > 0. And
  * will log errors to CakeLog, when debug == 0.
  *
  * You can use Configure::write('Error.level', $value); to set what type of errors will be handled here.
  * Stack traces for errors can be enabled with Configure::write('Error.trace', true);
  *
  * @param int $code Code of error
  * @param string $description Error description
  * @param string $file File on which error occurred
  * @param int $line Line that triggered the error
  * @param array $context Context
  * @return bool true if error was handled
  */
 public static function handleError($code, $description, $file = null, $line = null, $context = null)
 {
     if (error_reporting() === 0) {
         return false;
     }
     list($error, $log) = static::mapErrorCode($code);
     if ($log === LOG_ERR) {
         return static::handleFatalError($code, $description, $file, $line);
     }
     $debug = Configure::read('debug');
     if ($debug) {
         $data = array('level' => $log, 'code' => $code, 'error' => $error, 'description' => $description, 'file' => $file, 'line' => $line, 'context' => $context, 'start' => 2, 'path' => Debugger::trimPath($file));
         return Debugger::getInstance()->outputError($data);
     }
     $message = static::_getErrorMessage($error, $code, $description, $file, $line);
     return CakeLog::write($log, $message);
 }
 /**
  * Set as the default error handler by CakePHP. Use Configure::write('Error.handler', $callback), to use your own
  * error handling methods. This function will use Debugger to display errors when debug > 0. And
  * will log errors to CakeLog, when debug == 0.
  *
  * You can use Configure::write('Error.level', $value); to set what type of errors will be handled here.
  * Stack traces for errors can be enabled with Configure::write('Error.trace', true);
  *
  * @param int $code Code of error
  * @param string $description Error description
  * @param string $file File on which error occurred
  * @param int $line Line that triggered the error
  * @param array $context Context
  * @return bool true if error was handled
  */
 public static function handleError($code, $description, $file = null, $line = null, $context = null)
 {
     if (error_reporting() === 0) {
         return false;
     }
     $errorConfig = Configure::read('Error');
     list($error, $log) = static::mapErrorCode($code);
     if ($log === LOG_ERR) {
         return static::handleFatalError($code, $description, $file, $line);
     }
     $debug = Configure::read('debug');
     if ($debug) {
         $data = array('level' => $log, 'code' => $code, 'error' => $error, 'description' => $description, 'file' => $file, 'line' => $line, 'context' => $context, 'start' => 2, 'path' => Debugger::trimPath($file));
         return Debugger::getInstance()->outputError($data);
     }
     $message = $error . ' (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
     if (!empty($errorConfig['trace'])) {
         // https://bugs.php.net/bug.php?id=65322
         if (version_compare(PHP_VERSION, '5.4.21', '<')) {
             if (!class_exists('Debugger')) {
                 App::load('Debugger');
             }
             if (!class_exists('CakeText')) {
                 App::uses('CakeText', 'Utility');
                 App::load('CakeText');
             }
         }
         $trace = Debugger::trace(array('start' => 1, 'format' => 'log'));
         $message .= "\nTrace:\n" . $trace . "\n";
     }
     return CakeLog::write($log, $message);
 }
Пример #25
0
 /**
  * Set the error/exception handlers for the console
  * based on the `Error.consoleHandler`, and `Exception.consoleHandler` values
  * if they are set. If they are not set, the default ConsoleErrorHandler will be
  * used.
  *
  * @return void
  */
 public function setErrorHandlers()
 {
     App::uses('ConsoleErrorHandler', 'Console');
     $error = Configure::read('Error');
     $exception = Configure::read('Exception');
     $errorHandler = new ConsoleErrorHandler();
     if (empty($error['consoleHandler'])) {
         $error['consoleHandler'] = array($errorHandler, 'handleError');
         Configure::write('Error', $error);
     }
     if (empty($exception['consoleHandler'])) {
         $exception['consoleHandler'] = array($errorHandler, 'handleException');
         Configure::write('Exception', $exception);
     }
     set_exception_handler($exception['consoleHandler']);
     set_error_handler($error['consoleHandler'], Configure::read('Error.level'));
     App::uses('Debugger', 'Utility');
     Debugger::getInstance()->output('txt');
 }
Пример #26
0
 /**
  * Outputs a stack trace based on the supplied options.
  *
  * ### Options
  *
  * - `depth` - The number of stack frames to return. Defaults to 999
  * - `format` - The format you want the return. Defaults to the currently selected format. If
  *    format is 'array' or 'points' the return will be an array.
  * - `args` - Should arguments for functions be shown?  If true, the arguments for each method call
  *   will be displayed.
  * - `start` - The stack frame to start generating a trace from. Defaults to 0
  *
  * @param array $options Format for outputting stack trace
  *
  * @return mixed Formatted stack trace
  * @link http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::trace
  */
 public static function trace($options = array())
 {
     $self = Debugger::getInstance();
     $defaults = array('depth' => 999, 'format' => $self->_outputFormat, 'args' => FALSE, 'start' => 0, 'scope' => NULL, 'exclude' => array('call_user_func_array', 'trigger_error'));
     $options = Hash::merge($defaults, $options);
     $backtrace = debug_backtrace();
     $count = count($backtrace);
     $back = array();
     $_trace = array('line' => '??', 'file' => '[internal]', 'class' => NULL, 'function' => '[main]');
     for ($i = $options['start']; $i < $count && $i < $options['depth']; $i++) {
         $trace = array_merge(array('file' => '[internal]', 'line' => '??'), $backtrace[$i]);
         $signature = $reference = '[main]';
         if (isset($backtrace[$i + 1])) {
             $next = array_merge($_trace, $backtrace[$i + 1]);
             $signature = $reference = $next['function'];
             if (!empty($next['class'])) {
                 $signature = $next['class'] . '::' . $next['function'];
                 $reference = $signature . '(';
                 if ($options['args'] && isset($next['args'])) {
                     $args = array();
                     foreach ($next['args'] as $arg) {
                         $args[] = Debugger::exportVar($arg);
                     }
                     $reference .= implode(', ', $args);
                 }
                 $reference .= ')';
             }
         }
         if (in_array($signature, $options['exclude'])) {
             continue;
         }
         if ($options['format'] === 'points' && $trace['file'] !== '[internal]') {
             $back[] = array('file' => $trace['file'], 'line' => $trace['line']);
         } elseif ($options['format'] === 'array') {
             $back[] = $trace;
         } else {
             if (isset($self->_templates[$options['format']]['traceLine'])) {
                 $tpl = $self->_templates[$options['format']]['traceLine'];
             } else {
                 $tpl = $self->_templates['base']['traceLine'];
             }
             $trace['path'] = static::trimPath($trace['file']);
             $trace['reference'] = $reference;
             unset($trace['object'], $trace['args']);
             $back[] = CakeText::insert($tpl, $trace, array('before' => '{:', 'after' => '}'));
         }
     }
     if ($options['format'] === 'array' || $options['format'] === 'points') {
         return $back;
     }
     return implode("\n", $back);
 }
Пример #27
0
 /**
  * Overrides PHP's default error handling
  *
  * @param integer $code Code of error
  * @param string $description Error description
  * @param string $file File on which error occurred
  * @param integer $line Line that triggered the error
  * @param array $context Context
  * @return boolean true if error was handled
  * @access public
  */
 function handleError($code, $description, $file = null, $line = null, $context = null)
 {
     if (error_reporting() == 0 || $code === 2048) {
         return;
     }
     $_this = Debugger::getInstance();
     if (empty($file)) {
         $file = '[internal]';
     }
     if (empty($line)) {
         $line = '??';
     }
     $file = $_this->trimPath($file);
     $info = compact('code', 'description', 'file', 'line');
     if (!in_array($info, $_this->errors)) {
         $_this->errors[] = $info;
     } else {
         return;
     }
     $level = LOG_DEBUG;
     switch ($code) {
         case E_PARSE:
         case E_ERROR:
         case E_CORE_ERROR:
         case E_COMPILE_ERROR:
             $error = 'Fatal Error';
             $level = LOG_ERROR;
             break;
         case E_WARNING:
         case E_USER_WARNING:
         case E_COMPILE_WARNING:
         case E_RECOVERABLE_ERROR:
             $error = 'Warning';
             $level = LOG_WARNING;
             break;
         case E_NOTICE:
             $error = 'Notice';
             $level = LOG_NOTICE;
             break;
         default:
             return false;
             break;
     }
     $helpCode = null;
     if (!empty($_this->helpPath) && preg_match('/.*\\[([0-9]+)\\]$/', $description, $codes)) {
         if (isset($codes[1])) {
             $helpCode = $codes[1];
             $description = trim(preg_replace('/\\[[0-9]+\\]$/', '', $description));
         }
     }
     $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>");
             }
             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>');
     }
     if (Configure::read('log')) {
         CakeLog::write($level, "{$error} ({$code}): {$description} in [{$file}, line {$line}]");
     }
     if ($error == 'Fatal Error') {
         die;
     }
     return true;
 }