public function __construct($message = null, $code = 0, Exception $previous = null) { if (Configure::read('ModularAuth.debug_trace')) { $trace = "\n" . Debugger::trace(array('start' => 1)); var_dump($trace); } parent::__construct($message, $code, $previous); }
public static function getHtml($message, $file, $line, $context = null) { $params = Router::getRequest(); $trace = Debugger::trace(array('start' => 2, 'format' => 'base')); $session = isset($_SESSION) ? $_SESSION : array(); $msg = array('<p><strong>', $message, '</strong></p>', '<p>', $file . '(' . $line . ')', '</p>', '', '<h2>', 'Backtrace:', '</h2>', '', '<pre>', trim($trace), '</pre>', '', '<h2>', 'Request:', '</h2>', '', '<h3>URL</h3>', self::getUrl(), '<h3>Client IP</h3>', self::getClientIp(), '<h3>Referer</h3>', env('HTTP_REFERER'), '<h3>Parameters</h3>', self::dumper($params), '<h3>Cake root</h3>', APP, '', '<h2>', 'Environment:', '</h2>', '', self::dumper($_SERVER), '', '<h2>', 'Session:', '</h2>', '', self::dumper($session), '', '<h2>', 'Cookie:', '</h2>', '', self::dumper($_COOKIE), '', '<h2>', 'Context:', '</h2>', '', self::dumper($context), ''); return join("\n", $msg); }
/** * debug method * * Dump the classes variables * * @return void * @access public */ static function debug() { //@ignore debug(Debugger::trace()); //@ignore debug(Notify::$method); //@ignore debug(Notify::$statuses); //@ignore debug(Notify::$notifiers); //@ignore }
/** * Prints out debug information about given variable. * * Only runs if debug level is greater than zero. * * @param boolean $var Variable to show debug information for. * @param boolean $showHtml If set to true, the method prints the debug data in a browser-friendly way. * @param boolean $showFrom If set to true, the method prints from where the function was called. * @return void * @link http://book.cakephp.org/2.0/en/development/debugging.html#basic-debugging * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#debug */ function debug($var, $showHtml = null, $showFrom = true) { if (Configure::read('debug') > 0) { App::uses('Debugger', 'Utility'); $file = ''; $line = ''; $lineInfo = ''; if ($showFrom) { $trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array')); $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']); $line = $trace[0]['line']; } $html = <<<HTML <div class="cake-debug-output"> %s <pre class="cake-debug"> %s </pre> </div> HTML; $text = <<<TEXT %s ########## DEBUG ########## %s ########################### TEXT; $template = $html; if (php_sapi_name() === 'cli' || $showHtml === false) { $template = $text; if ($showFrom) { $lineInfo = sprintf('%s (line %s)', $file, $line); } } if ($showHtml === null && $template !== $text) { $showHtml = true; } $var = Debugger::exportVar($var, 25); if ($showHtml) { $template = $html; $var = h($var); if ($showFrom) { $lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line); } } printf($template, $lineInfo, $var); } }
/** * 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); } }
/** * Undo Mi logic when reporting an error for a missing view file * * @param mixed $name * @param array $params array() * @param bool $loadHelpers false * @return void * @access public */ public function element($name, $params = array(), $loadHelpers = false) { $return = parent::element($name, $params, $loadHelpers); if (strpos($return, 'Not Found:') === 0) { $plugin = null; if (isset($params['plugin'])) { $plugin = $params['plugin']; } if (isset($this->plugin) && !$plugin) { $plugin = $this->plugin; } $paths = $this->_paths($plugin); $path = array_pop($paths); while ($paths && strpos($path, DS . 'locale' . DS)) { $path = array_pop($paths); } $file = $path . 'elements' . DS . $name . $this->ext; $trace = Debugger::trace(); return "Not Found: " . $file . $trace; } return $return; }
/** * HandleError * * @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 */ public static function handleError($code, $description, $file = null, $line = null, $context = null) { extract(self::handlerSettings()); $args = compact('code', 'description', 'file', 'line', 'context', 'session'); if ($emailNotifications === true && !empty($receiver)) { $cacheHash = 'error-' . md5(serialize(compact($args))); self::setCacheConfig($duration); if (Cache::read($cacheHash, 'error_handler') === false || $caching === false) { list($error, $log) = self::mapErrorCode($code); if (in_array($log, $logLevels) || in_array($code, $codes)) { $trace = Debugger::trace(array('start' => 1, 'format' => 'log')); $session = CakeSession::read(); $server = $_SERVER; $request = $_REQUEST; $Email = self::getEmailInstance(); $Email->viewVars(compact('code', 'description', 'file', 'line', 'context', 'session', 'server', 'request', 'trace')); $Email->send(); } Cache::write($cacheHash, true, 'error_handler'); } } return parent::handleError($code, $description, $file, $line, $context); }
function __dispatch($name) { $debug = Configure::read('debug') > 0; if ($debug) { var_dump(Debugger::trace()); $this->controller->layout = 'cakephp'; } if (empty($this->controller->viewVars['name'])) { $this->controller->set('name', __('Not Found', true)); $this->controller->set('message', $debug ? h(Router::normalize($this->controller->here)) : ''); } switch ($name) { case 'error500': case 'forbidden': return $name; default: if (Configure::read() === 0) { return 'error404'; } else { return $name; } } }
/** * Class constructor. * * @param string $method Method producing the error * @param array $messages Error messages */ function __construct($method, $messages) { App::import('Core', 'Sanitize'); static $__previousError = null; if ($__previousError != array($method, $messages)) { $__previousError = array($method, $messages); $this->controller =& new CakeErrorController(); } else { $this->controller =& new Controller(); $this->controller->viewPath = 'errors'; } $options = array('escape' => false); $messages = Sanitize::clean($messages, $options); if (!isset($messages[0])) { $messages = array($messages); } if (method_exists($this->controller, 'apperror')) { return $this->controller->appError($method, $messages); } if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($this)))) { $method = 'error'; } if (!in_array($method, array('error'))) { if (Configure::read() == 0) { $method = 'error404'; if (isset($code) && $code == 500) { $method = 'error500'; } } } if (defined('CAKE_TEST_OUTPUT_HTML')) { $this->controller->layout = 'ajax'; debug(Debugger::trace()); } $this->dispatchMethod($method, $messages); $this->_stop(); }
/** * Utility Exec method * * @param mixed $cmd * @param mixed $output * @return void * @access public */ public function exec($cmd, &$out = array()) { if (DS === '/') { $_out = exec($cmd . ' 2>&1', $out, $return); } else { $_out = exec($cmd, $out, $return); } if (Configure::read()) { $source = Debugger::trace(array('depth' => 1, 'start' => 2)) . "\n"; CakeLog::write('system_calls_' . date('Y-m-d'), "\n" . $source . Debugger::exportVar(compact('cmd', 'out', 'return'))); CakeLog::write('system_calls', "\n" . $source . Debugger::exportVar(compact('cmd', 'out', 'return'))); } if ($return) { return false; } return $_out ? $_out : true; }
/** * Generate the string to use to describe the error. * * @param string $error The error type (e.g. "Warning") * @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 * @return string */ protected static function _getErrorMessage($error, $code, $description, $file, $line) { $errorConfig = Configure::read('Error'); $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 $message; }
/** * isAuthorized method * * Called only for the emails controller view action - restricts viewing an email on the web to 'normal' emails and * only for admin, the author or the recipient. The model id is set in the emails controller beforeFilter. * * @param mixed $user * @param mixed $controller * @param mixed $action * @return bool * @access public */ public function isAuthorized($user, $controller, $action) { if ($controller != 'MiEmail' || $action != 'read') { debug('Email model isAuthorized has been called'); //@ignore debug(Debugger::trace()); //@ignore return false; } if (strtolower($user['User']['group']) == 'admin') { return true; } elseif (!$this->id) { return false; } $data = $this->read(array('from_user_id', 'to_user_id', 'type')); $validUsers = array($data[$this->alias]['to_user_id'], $data[$this->alias]['from_user_id']); if ($data[$this->alias]['type'] == 'normal' && in_array($user['User']['id'], $validUsers)) { return true; } return false; }
/** * testInstantiation method * * @access public * @return void */ function testInstantiation() { $this->skipUnless(strpos(Debugger::trace(), 'GroupTest') === false, '%s Cannot be run from within a group test'); $Instance = Inflector::getInstance(); $this->assertEqual(new Inflector(), $Instance); }
/** * Tests that changes in output formats using Debugger::output() change the templates used. * * @return void */ function testChangeOutputFormats() { Debugger::invoke(Debugger::getInstance()); Debugger::output('js', array('traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' . '&line={:line}">{:path}</a>, line {:line}')); $result = Debugger::trace(); $this->assertPattern('/' . preg_quote('txmt://open?url=file:///', '/') . '/', $result); Debugger::output('xml', array('error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' . '{:description}</error>', 'context' => "<context>{:context}</context>", 'trace' => "<stack>{:trace}</stack>")); Debugger::output('xml'); ob_start(); $foo .= ''; $result = ob_get_clean(); set_error_handler('SimpleTestErrorHandler'); $data = array('error' => array(), 'code' => array(), '8', '/code', 'file' => array(), 'preg:/[^<]+/', '/file', 'line' => array(), '' . (intval(__LINE__) + -8), '/line', 'preg:/Undefined variable:\\s+foo/', '/error'); $this->assertTags($result, $data, true); }
/** * Outputs a stack trace based on the supplied options. * * ### Options * * - `depth` - The number of stack frames to return. Defaults to 999 * - `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 1 * * @param array $options Format for outputting stack trace * * @return mixed Formatted stack trace * @see Debugger::trace() */ function stackTrace(array $options = array()) { if (!Configure::read('debug')) { return; } App::uses('Debugger', 'Utility'); $options += array('start' => 0); $options['start']++; echo Debugger::trace($options); }
/** * Logs some debug output. * * @return void */ private function _debug($o) { if ($this->enableDebug) { $ds = str_repeat('-', 4); error_log(implode("\n", array('Begin debug output... ', "{$ds}Var Export{$ds}", Debugger::exportVar($o), "{$ds}Stack Trace{$ds}", Debugger::trace()))); } }
/** * Tests that the stackTrace() method is a shortcut for Debugger::trace() * * @return void */ public function testStackTrace() { ob_start(); list(, $expected) = array(stackTrace(), Debugger::trace()); $result = ob_get_clean(); $this->assertEquals($expected, $result); $opts = array('args' => true); ob_start(); list(, $expected) = array(stackTrace($opts), Debugger::trace($opts)); $result = ob_get_clean(); $this->assertEquals($expected, $result); }
public function staticCall() { return Debugger::trace(); }
/** * test trace exclude * * @return void */ public function testTraceExclude() { $result = Debugger::trace(); $this->assertRegExp('/^DebuggerTest::testTraceExclude/', $result); $result = Debugger::trace(array('exclude' => array('DebuggerTest::testTraceExclude'))); $this->assertNotRegExp('/^DebuggerTest::testTraceExclude/', $result); }
/** * 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); }
/** * Tests that changes in output formats using Debugger::output() change the templates used. * * @return void */ public function testAddFormat() { set_error_handler('Debugger::showError'); $this->_restoreError = true; Debugger::addFormat('js', array( 'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' . '&line={:line}">{:path}</a>, line {:line}' )); Debugger::outputAs('js'); $result = Debugger::trace(); $this->assertPattern('/' . preg_quote('txmt://open?url=file://', '/') . '(\/|[A-Z]:\\\\)' . '/', $result); Debugger::addFormat('xml', array( 'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' . '{:description}</error>', )); Debugger::outputAs('xml'); ob_start(); $foo .= ''; $result = ob_get_clean(); $data = array( '<error', '<code', '8', '/code', '<file', 'preg:/[^<]+/', '/file', '<line', '' . (intval(__LINE__) - 7), '/line', 'preg:/Undefined variable:\s+foo/', '/error' ); $this->assertTags($result, $data, true); }
/** * alias method * * checks for an alias/slug and returns sends a new dispatch if found * otherwise throws the not found exception like it would have anyway * * @return void */ protected function _alias($request, $exception = null) { try { $Alias = ClassRegistry::init('Alias'); $alias = $Alias->find('first', array('conditions' => array('Alias.name' => trim(urldecode($request->here), "/")))); } catch (Exception $e) { // trying to show the original exception if it exists debug($exception); // this will probably always be missing alias table or something to do with alias debug($e->getMessage()); // in some rare cases this is a hard to find error debug(Debugger::trace()); exit; } if (!empty($alias)) { $request->params['controller'] = $alias['Alias']['controller']; $request->params['plugin'] = $alias['Alias']['plugin']; $request->params['action'] = $alias['Alias']['action']; $request->params['pass'][] = $alias['Alias']['value']; $request->params['alias'] = $alias['Alias']['name']; $request->url = '/'; !empty($alias['Alias']['plugin']) ? $request->url = $request->url . $alias['Alias']['plugin'] . '/' : ''; !empty($alias['Alias']['controller']) ? $request->url = $request->url . $alias['Alias']['controller'] . '/' : ''; !empty($alias['Alias']['action']) ? $request->url = $request->url . $alias['Alias']['action'] . '/' : ''; !empty($alias['Alias']['value']) ? $request->url = $request->url . $alias['Alias']['value'] . '/' : ''; // this $request->query['url'] = $request->url; $request->here = $request->url; // was this (changed after Cake2.4 because the login redirect wasn't playing nice) // $request->query['url'] = substr($request->url, 1, -1); // $request->here = substr($request->url, 1, -1); $dispatcher = new Dispatcher(); $dispatcher->dispatch($request, new CakeResponse()); } else { throw new NotFoundException('Page not found.'); } exit; }
/** * 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); }
/** * own shutdown function - also logs fatal errors (necessary until cake2.2) * 2010-10-17 ms */ function shutDownFunction() { $error = error_get_last(); if (empty($error)) { return; } $matching = array(E_ERROR => 'E_ERROR', E_WARNING => 'E_WARNING', E_PARSE => 'E_', E_NOTICE => 'E_', E_CORE_ERROR => 'E_', E_COMPILE_ERROR => 'E_', E_COMPILE_WARNING => 'E_', E_STRICT => 'E_STRICT', E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', E_DEPRECATED => 'E_DEPRECATED'); App::uses('CakeLog', 'Log'); if (in_array($error['type'], array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR))) { $error['type_name'] = 'Fatal Error'; $type = 'error'; } elseif (Configure::read('Debug.log') && isset($matching[$error['type']])) { $error['type_name'] = 'Error'; $type = 'notice'; } if (!isset($type)) { return; } App::uses('Debugger', 'Utility'); $trace = Debugger::trace(array('start' => 1, 'format' => 'log', 'args' => true)); $path = Debugger::trimPath($error['file']); $message = $error['type_name'] . ' ' . $matching[$error['type']] . ' in ' . $path . ' (line ' . $error['line'] . '): ' . $error['message']; $message .= PHP_EOL . $trace; App::uses('MyErrorHandler', 'Tools.Error'); $message .= MyErrorHandler::traceDetails(); CakeLog::write($type, $message); }