当前位置: 首页>>代码示例>>PHP>>正文


PHP Throwable::getTrace方法代码示例

本文整理汇总了PHP中Throwable::getTrace方法的典型用法代码示例。如果您正苦于以下问题:PHP Throwable::getTrace方法的具体用法?PHP Throwable::getTrace怎么用?PHP Throwable::getTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Throwable的用法示例。


在下文中一共展示了Throwable::getTrace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get

 /**
  * @inheritDoc
  */
 public function get()
 {
     if (!isset($this->throwable)) {
         throw new LogicException('Throwable must be set to get view.');
     }
     ob_start();
     var_dump($this->throwable->getTrace());
     $fullTrace = ob_get_clean();
     // If xdebug is installed then var_dump is pretty printed for html already.
     if (function_exists('xdebug_var_dump')) {
         $viewTrace = new Text();
         $viewTrace->setHTML5($fullTrace);
         $fullTrace = ['div', ['class' => 'full_trace'], $viewTrace->get()];
     } else {
         $fullTrace = ['pre', ['class' => 'full_trace'], $fullTrace];
     }
     return ['div', ['class' => 'Throwable'], [['div', ['class' => 'location'], 'Thrown at ' . $this->throwable->getFile() . ' line ' . $this->throwable->getLine()], ['pre', [], $this->throwable->getMessage()], ['h2', [], 'Basic Trace'], ['pre', ['class' => 'basic_trace'], $this->throwable->getTraceAsString()], ['h2', [], 'Full Trace'], $fullTrace]];
 }
开发者ID:evoke-php,项目名称:evoke-php,代码行数:21,代码来源:Throwable.php

示例2: testPrepareStep

 /**
  * @dataProvider providerTestPrepareStep
  * @param HtmlHelper $helper
  * @param \Exception|\Throwable $exception
  */
 public function testPrepareStep(HtmlHelper $helper, $exception)
 {
     foreach ($exception->getTrace() as $step) {
         $colorized = $helper->prepareStep($step);
         $this->assertTrue(is_array($colorized));
         foreach (array('title', 'source', 'key', 'arguments') as $key) {
             $this->assertTrue(isset($colorized[$key]));
         }
         $this->assertTrue(is_array($colorized['arguments']));
     }
 }
开发者ID:bkrukowski,项目名称:error-dumper,代码行数:16,代码来源:HtmlHelperTest.php

示例3: handle_exception

 /**
  * @param \Exception|\Throwable $exception
  */
 public function handle_exception($exception)
 {
     if (getenv('APP_ENV') === 'dev') {
         list($code, $file, $line, $message, $previous, $trace, $trace_string) = [$exception->getCode(), $exception->getFile(), $exception->getLine(), $exception->getMessage(), $exception->getPrevious(), $exception->getTrace(), $exception->getTraceAsString()];
         $trace_info = "<b>file</b>: {$trace[0]['file']} <b>in line</b> ({$trace[0]['line']})";
         echo "<h2>COGS Runtime Exception: [::{$code}] {$message}</h2>";
         echo "<b>Trace:</b><br>";
         echo "<pre>{$trace_string}</pre>";
         echo "<b>Debug:</b><br>";
         dump(compact('code', 'file', 'line', 'message', 'previous', 'trace'));
     }
 }
开发者ID:anctemarry27,项目名称:cogs,代码行数:15,代码来源:ErrorHandlingServiceProvider.php

示例4: __construct

 public function __construct(\Throwable $e)
 {
     if ($e instanceof \ParseError) {
         $message = 'Parse error: ' . $e->getMessage();
         $severity = E_PARSE;
     } elseif ($e instanceof \TypeError) {
         $message = 'Type error: ' . $e->getMessage();
         $severity = E_RECOVERABLE_ERROR;
     } else {
         $message = $e->getMessage();
         $severity = E_ERROR;
     }
     \ErrorException::__construct($message, $e->getCode(), $severity, $e->getFile(), $e->getLine());
     $this->setTrace($e->getTrace());
 }
开发者ID:zanderbaldwin,项目名称:symfony,代码行数:15,代码来源:FatalThrowableError.php

示例5: error_log

 /**
  * 记录起始请求日志
  * 记录成功返回true,失败或没记录日志返回false
  *
  * @param  \Exception|\Throwable   $ex
  * @return  bool
  */
 public static function error_log($ex)
 {
     if (!BaseLog::isLog('error')) {
         return false;
     }
     if (!Config::getEnv("app.framework_error_log")) {
         return false;
     }
     $data = Request::nonPostParam();
     if (Config::getEnv("app.request_log_post")) {
         $data = Request::param();
     }
     $log_msg = "\r\nQP->Main最外层捕捉到Exception异常:\r\n请求参数:{Param}\r\n异常信息:{E_Msg}\r\n异常位置:{E_Point}\r\n更多异常队列信息:{E_Trace}\r\n";
     $log_data = ['Param' => json_encode($data), 'E_Msg' => $ex->getMessage(), 'E_Point' => $ex->getFile() . ":" . $ex->getLine(), 'E_Trace' => json_encode($ex->getTrace())];
     return Log::error($log_msg, $log_data, true, 'framework');
 }
开发者ID:q-phalcon,项目名称:kernel,代码行数:23,代码来源:SystemLog.php

示例6: renderBacktrace

 /**
  * Render the backtrace
  *
  * @return  string  The contents of the backtrace
  *
  * @since   11.1
  */
 public function renderBacktrace()
 {
     // If no error object is set return null
     if (!isset($this->_error)) {
         return;
     }
     $contents = null;
     $backtrace = $this->_error->getTrace();
     if (is_array($backtrace)) {
         ob_start();
         $j = 1;
         echo '<table cellpadding="0" cellspacing="0" class="Table">';
         echo '	<tr>';
         echo '		<td colspan="3" class="TD"><strong>Call stack</strong></td>';
         echo '	</tr>';
         echo '	<tr>';
         echo '		<td class="TD"><strong>#</strong></td>';
         echo '		<td class="TD"><strong>Function</strong></td>';
         echo '		<td class="TD"><strong>Location</strong></td>';
         echo '	</tr>';
         for ($i = count($backtrace) - 1; $i >= 0; $i--) {
             echo '	<tr>';
             echo '		<td class="TD">' . $j . '</td>';
             if (isset($backtrace[$i]['class'])) {
                 echo '	<td class="TD">' . $backtrace[$i]['class'] . $backtrace[$i]['type'] . $backtrace[$i]['function'] . '()</td>';
             } else {
                 echo '	<td class="TD">' . $backtrace[$i]['function'] . '()</td>';
             }
             if (isset($backtrace[$i]['file'])) {
                 echo '		<td class="TD">' . $backtrace[$i]['file'] . ':' . $backtrace[$i]['line'] . '</td>';
             } else {
                 echo '		<td class="TD">&#160;</td>';
             }
             echo '	</tr>';
             $j++;
         }
         echo '</table>';
         $contents = ob_get_contents();
         ob_end_clean();
     }
     return $contents;
 }
开发者ID:Rai-Ka,项目名称:joomla-cms,代码行数:49,代码来源:error.php

示例7: exceptionHandler

 public function exceptionHandler(\Throwable $exception)
 {
     $message = $exception->getMessage();
     $values = $exception->getTrace();
     $traces = [];
     $trace = new Trace();
     $trace->setFile($exception->getFile());
     $trace->setLine($exception->getLine());
     $trace->setClass(get_class($exception));
     $traces[] = $trace;
     foreach ($values as $value) {
         $trace = new Trace();
         $trace->setFile($this->getArrayValue($value, "file"));
         $trace->setLine($this->getArrayValue($value, "line"));
         $trace->setFunction($this->getArrayValue($value, "function"));
         $trace->setClass($this->getArrayValue($value, "class"));
         $traces[] = $trace;
     }
     $this->log($message, $traces);
 }
开发者ID:wispira,项目名称:framework,代码行数:20,代码来源:Handler.php

示例8: getResponseFormat

 /**
  * Method that returns a response in the request format
  *
  * @todo Customize according to project
  * @param string $message Error message
  * @param int $status Status code
  * @param \Exception $exception Exception caught
  * @return JsonResponse|HtmlResponse
  */
 public function getResponseFormat($message, $status, \Throwable $exception)
 {
     if (count($this->accept) > 0 && $this->accept[0] == 'application/json') {
         $data = ['status' => $status, 'error' => ['msg' => $message]];
         if ($this->debug) {
             $data['error']['debug']['msg'] = $exception->getMessage();
             $data['error']['debug']['file'] = $exception->getFile();
             $data['error']['debug']['line'] = $exception->getLine();
             $data['error']['debug']['trace'] = $exception->getTrace();
         }
         return new JsonResponse($data, $status);
     }
     $msg = $message;
     if ($this->debug) {
         $msg .= '<br />Description: ' . $exception->getMessage();
         $msg .= '<br />File: ' . $exception->getFile();
         $msg .= '<br />Line: ' . $exception->getLine();
         $msg .= '<br />Trace: ' . $exception->getTraceAsString();
     }
     return new HtmlResponse($msg, $status);
 }
开发者ID:danielspk,项目名称:tornadohttpskeletonapplication,代码行数:30,代码来源:Handler.php

示例9: getTraceAsString

 /**
  * @param DefinitionInterface $definition
  * @param \Throwable          $exception
  * @return string
  */
 private function getTraceAsString(DefinitionInterface $definition, $exception) : string
 {
     $stringParts = [];
     $previousStep = [];
     $enableColoredOutput = $this->getEnableColoredOutput();
     $stackTrace = $exception->getTrace();
     $stackTraceCount = count($stackTrace);
     for ($i = 0; $i < $stackTraceCount; $i++) {
         $step = $stackTrace[$i];
         if ($this->shouldStopTraceAtStep($step)) {
             break;
         }
         $stepAsString = $this->getTraceStepAsString($step, $i);
         if ($enableColoredOutput && $this->getTraceStepIsTestMethod($definition, $step, $previousStep)) {
             $stringParts[] = self::NORMAL . self::RED_BACKGROUND . $stepAsString . self::RED;
         } else {
             $stringParts[] = $stepAsString;
         }
         $previousStep = $step;
     }
     return implode("\n", $stringParts);
 }
开发者ID:cundd,项目名称:test-flight,代码行数:27,代码来源:ExceptionPrinter.php

示例10: decodeException

 /**
  * Decodes an exception and retrieves the correct caller.
  *
  * @param \Exception|\Throwable $exception
  *   The exception object that was thrown.
  *
  * @return array
  *   An error in the format expected by _drupal_log_error().
  */
 public static function decodeException($exception)
 {
     $message = $exception->getMessage();
     $backtrace = $exception->getTrace();
     // Add the line throwing the exception to the backtrace.
     array_unshift($backtrace, array('line' => $exception->getLine(), 'file' => $exception->getFile()));
     // For PDOException errors, we try to return the initial caller,
     // skipping internal functions of the database layer.
     if ($exception instanceof \PDOException || $exception instanceof DatabaseExceptionWrapper) {
         // The first element in the stack is the call, the second element gives us
         // the caller. We skip calls that occurred in one of the classes of the
         // database layer or in one of its global functions.
         $db_functions = array('db_query', 'db_query_range');
         while (!empty($backtrace[1]) && ($caller = $backtrace[1]) && (isset($caller['class']) && (strpos($caller['class'], 'Query') !== FALSE || strpos($caller['class'], 'Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE) || in_array($caller['function'], $db_functions))) {
             // We remove that call.
             array_shift($backtrace);
         }
         if (isset($exception->query_string, $exception->args)) {
             $message .= ": " . $exception->query_string . "; " . print_r($exception->args, TRUE);
         }
     }
     $caller = static::getLastCaller($backtrace);
     return array('%type' => get_class($exception), '@message' => $message, '%function' => $caller['function'], '%file' => $caller['file'], '%line' => $caller['line'], 'severity_level' => static::ERROR, 'backtrace' => $backtrace, '@backtrace_string' => $exception->getTraceAsString());
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:33,代码来源:Error.php

示例11: logException

 public function logException(\Throwable $e, $trace = null)
 {
     if ($trace === null) {
         $trace = $e->getTrace();
     }
     $errstr = $e->getMessage();
     $errfile = $e->getFile();
     $errno = $e->getCode();
     $errline = $e->getLine();
     $errorConversion = [0 => "EXCEPTION", E_ERROR => "E_ERROR", E_WARNING => "E_WARNING", E_PARSE => "E_PARSE", E_NOTICE => "E_NOTICE", E_CORE_ERROR => "E_CORE_ERROR", E_CORE_WARNING => "E_CORE_WARNING", E_COMPILE_ERROR => "E_COMPILE_ERROR", E_COMPILE_WARNING => "E_COMPILE_WARNING", E_USER_ERROR => "E_USER_ERROR", E_USER_WARNING => "E_USER_WARNING", E_USER_NOTICE => "E_USER_NOTICE", E_STRICT => "E_STRICT", E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", E_DEPRECATED => "E_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED"];
     if ($errno === 0) {
         $type = LogLevel::CRITICAL;
     } else {
         $type = ($errno === E_ERROR or $errno === E_USER_ERROR) ? LogLevel::ERROR : (($errno === E_USER_WARNING or $errno === E_WARNING) ? LogLevel::WARNING : LogLevel::NOTICE);
     }
     $errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno;
     if (($pos = strpos($errstr, "\n")) !== false) {
         $errstr = substr($errstr, 0, $pos);
     }
     $errfile = \pocketmine\cleanPath($errfile);
     $this->log($type, get_class($e) . ": \"{$errstr}\" ({$errno}) in \"{$errfile}\" at line {$errline}");
     foreach (@\pocketmine\getTrace(1, $trace) as $i => $line) {
         $this->debug($line);
     }
 }
开发者ID:iTXTech,项目名称:Genisys,代码行数:25,代码来源:MainLogger.php

示例12: throwableToArray

/**
 * Convert an Exception or Error into an array (for logging)
 *
 * @param \Throwable $ex
 * @return array
 */
function throwableToArray(\Throwable $ex) : array
{
    $prev = $ex->getPrevious();
    return ['line' => $ex->getLine(), 'file' => $ex->getFile(), 'message' => $ex->getMessage(), 'code' => $ex->getCode(), 'trace' => $ex->getTrace(), 'previous' => $prev ? throwableToArray($prev) : null];
}
开发者ID:paragonie,项目名称:airship,代码行数:11,代码来源:Airship.php

示例13: log

 /**
  * Log the Exception / Error thrown
  *
  * @param      \Throwable  $t      The Exception / Error thrown
  */
 public function log(\Throwable $t)
 {
     $this->logger->log($t->getCode(), $t->getMessage(), $t->getTrace());
 }
开发者ID:ZiperRom1,项目名称:awesomeChatRoom,代码行数:9,代码来源:ThrowableManager.php

示例14: exceptionStackTrace

 /**
  * @param \Throwable $exception
  *
  * @return array
  */
 protected function exceptionStackTrace(\Throwable $exception) : array
 {
     $return = [];
     $line = $exception->getLine();
     $file = $exception->getFile();
     $trace = $exception->getTrace();
     foreach (explode("\n", $exception->getTraceAsString()) as $currentLine) {
         $row = explode(' ', $currentLine);
         $stack = ['file' => null];
         $buffer = null;
         $index = trim(array_shift($row), '#');
         foreach ($row as $current) {
             // current file
             if (is_null($stack['file'])) {
                 if (substr($current, -1) === ':') {
                     $stack['file'] = trim($buffer ? $buffer . $current : $current, ':');
                     if (preg_match('`([^\\(]+)\\(([0-9]+)\\)`', $stack['file'], $matches)) {
                         $stack['file'] = $matches[1];
                         $stack['line'] = (int) $matches[2];
                     }
                 } else {
                     $buffer .= $current . ' ';
                 }
             } elseif (!isset($stack['function'])) {
                 $stack['function'] = strstr($current, '(', true);
                 $explodeString = strpos($stack['function'], '::') !== false ? '::' : '->';
                 $explode = explode($explodeString, $stack['function']);
                 if (sizeof($explode) > 1) {
                     $stack['class'] = $explode[0];
                     $stack['type'] = $explodeString;
                     $stack['function'] = $explode[1];
                     if (strpos($stack['class'], '\\') !== false) {
                         $explode = explode('\\', $stack['class']);
                         $stack['class'] = array_pop($explode);
                         $stack['namespace'] = implode('\\', $explode);
                     }
                 } elseif (strpos($stack['function'], '\\') !== false) {
                     $explode = explode('\\', $stack['function']);
                     $stack['function'] = array_pop($explode);
                     $stack['namespace'] = implode('\\', $explode);
                 }
                 $stack['args'] = strstr($current, '(') . ' ';
             } else {
                 $stack['args'] .= $current . ' ';
             }
         }
         if (is_null($stack['file'])) {
             $stack['file'] = $row[0];
         }
         $skip = false;
         // hack to hide error handler
         if (isset($stack['namespace']) && isset($stack['class'])) {
             if ($stack['namespace'] == 'Cawa\\Error' && $stack['class'] == 'Handler') {
                 $skip = true;
             }
         }
         // hack to hide backtrace call
         if (isset($stack['function']) && $stack['function'] == 'backtrace') {
             $skip = true;
             $file = $stack['file'];
             $line = (int) $stack['line'];
         }
         if ($skip == false) {
             if (isset($trace[$index]) && isset($trace[$index]['args'])) {
                 $stack['fullargs'] = $trace[$index]['args'];
             }
             $return[] = $stack;
         }
     }
     $return[0]['line'] = $line;
     $return[0]['file'] = $file;
     return $return;
 }
开发者ID:cawaphp,项目名称:cawa,代码行数:78,代码来源:AbstractFormatter.php

示例15: build_exception_frames

 /**
  * @param \Throwable|\Exception $exc
  * @return array
  */
 protected function build_exception_frames($exc)
 {
     $frames = array();
     foreach ($exc->getTrace() as $frame) {
         $framedata = array('filename' => isset($frame['file']) ? $frame['file'] : '<internal>', 'lineno' => isset($frame['line']) ? $frame['line'] : 0, 'method' => $frame['function']);
         if ($this->include_exception_code_context && isset($frame['file']) && isset($frame['line'])) {
             $this->add_frame_code_context($frame['file'], $frame['line'], $framedata);
         }
         $frames[] = $framedata;
     }
     // rollbar expects most recent call to be last, not first
     $frames = array_reverse($frames);
     // add top-level file and line to end of the reversed array
     $file = $exc->getFile();
     $line = $exc->getLine();
     $framedata = array('filename' => $file, 'lineno' => $line);
     if ($this->include_exception_code_context) {
         $this->add_frame_code_context($file, $line, $framedata);
     }
     $frames[] = $framedata;
     $this->shift_method($frames);
     return $frames;
 }
开发者ID:boboldehampsink,项目名称:rollbar,代码行数:27,代码来源:rollbar.php


注:本文中的Throwable::getTrace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。