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


PHP FlattenException::getTrace方法代码示例

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


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

示例1: getTrace

 public function getTrace($previewLines = 3)
 {
     $trace = parent::getTrace();
     if (!is_array($trace)) {
         return;
     }
     $trace[1]['file'] = $this->getFile();
     $trace[1]['line'] = $this->getLine();
     if ($previewLines === false) {
         return $trace;
     }
     foreach ($trace as &$item) {
         if (!$item['file'] || !$item['line']) {
             continue;
         }
         $item['file_preview'] = [];
         $fileContents = file_get_contents($item['file']);
         $fileContents = explode("\n", $fileContents);
         $firstLine = max($item['line'] - $previewLines, 1);
         $lastLine = min($item['line'] + $previewLines, count($fileContents));
         for ($line = $firstLine; $line <= $lastLine; $line++) {
             $item['file_preview'][$line] = $fileContents[$line - 1];
         }
     }
     return $trace;
 }
开发者ID:itsgoingd,项目名称:harmony,代码行数:26,代码来源:FlattenException.php

示例2: exceptionAction

 public function exceptionAction(FlattenException $exception)
 {
     $this->view->status_code = $exception->getStatusCode();
     $this->view->message = $exception->getMessage();
     $this->view->file = $this->getShortFileName($exception->getFile());
     $this->view->line = $exception->getLine();
     $this->view->trace = $this->parseTrace($exception->getTrace());
     return $this->renderTo('@HideksFramework/templates/exception.html');
 }
开发者ID:hidekscorporation,项目名称:hideksframework2,代码行数:9,代码来源:ErrorController.php

示例3: showAction

 /**
  * {@inheritdoc}
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $class = $exception->getClass();
     //ignore authentication exceptions
     if (strpos($class, 'Authentication') === false) {
         $env = $this->factory->getEnvironment();
         $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
         $layout = $env == 'prod' ? 'Error' : 'Exception';
         $code = $exception->getStatusCode();
         if ($code === 0) {
             //thrown exception that didn't set a code
             $code = 500;
         }
         // Special handling for oauth and api urls
         if (strpos($request->getUri(), '/oauth') !== false && strpos($request->getUri(), 'authorize') === false || strpos($request->getUri(), '/api') !== false) {
             $dataArray = array('error' => array('message' => $exception->getMessage(), 'code' => $code));
             if ($env == 'dev') {
                 $dataArray['trace'] = $exception->getTrace();
             }
             return new JsonResponse($dataArray, 200);
         }
         if ($request->get('prod')) {
             $layout = 'Error';
         }
         $anonymous = $this->factory->getSecurity()->isAnonymous();
         $baseTemplate = 'MauticCoreBundle:Default:slim.html.php';
         if ($anonymous) {
             if ($templatePage = $this->factory->getTheme()->getErrorPageTemplate($code)) {
                 $baseTemplate = $templatePage;
             }
         }
         $template = "MauticCoreBundle:{$layout}:{$code}.html.php";
         $templating = $this->factory->getTemplating();
         if (!$templating->exists($template)) {
             $template = "MauticCoreBundle:{$layout}:base.html.php";
         }
         $statusText = isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '';
         $url = $request->getRequestUri();
         $urlParts = parse_url($url);
         return $this->delegateView(array('viewParameters' => array('baseTemplate' => $baseTemplate, 'status_code' => $code, 'status_text' => $statusText, 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'isPublicPage' => $anonymous), 'contentTemplate' => $template, 'passthroughVars' => array('error' => array('code' => $code, 'text' => $statusText, 'exception' => $env == 'dev' ? $exception->getMessage() : '', 'trace' => $env == 'dev' ? $exception->getTrace() : ''), 'route' => $urlParts['path'])));
     }
 }
开发者ID:Jandersolutions,项目名称:mautic,代码行数:45,代码来源:ExceptionController.php

示例4: getContent

 public function getContent(FlattenException $exception)
 {
     if ($exception->getStatusCode() == '500') {
         $this->logger->error($exception->getMessage(), ['code' => $exception->getCode(), 'trace' => $exception->getTrace()]);
     }
     switch (true) {
         case 404 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Sorry, the page you are looking for could not be found.');
             } else {
                 $title = 'Sorry, the page you are looking for could not be found.';
             }
             break;
         case 403 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Sorry, you do have access to the page you are looking for.');
             } else {
                 $title = 'Sorry, you do have access to the page you are looking for.';
             }
             break;
         case 500 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Whoops, looks like something went wrong.');
             } else {
                 $title = 'Whoops, looks like something went wrong.';
             }
             break;
         case 503 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Sorry, site is currently undergoing maintenance, come back soon.');
             } else {
                 $title = 'Sorry, site is currently undergoing maintenance, come back soon.';
             }
             break;
         case isset(Response::$statusTexts[$exception->getStatusCode()]):
             $title = $exception->getStatusCode() . ' : ' . Response::$statusTexts[$exception->getStatusCode()];
             break;
         default:
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Whoops, looks like something went wrong.');
             } else {
                 $title = 'Whoops, looks like something went wrong.';
             }
     }
     $content = parent::getContent($exception);
     $start = strpos($content, '</h1>');
     $content = '<div id="sf-resetcontent" class="sf-reset">' . '<h1><span>' . $title . '</span></h1>' . substr($content, $start + 5);
     return $content;
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:49,代码来源:PhraseaExceptionHandler.php

示例5: decodeException

 /**
  * This method is a temporary port of _drupal_decode_exception().
  *
  * @todo This should get refactored. FlattenException could use some
  *   improvement as well.
  *
  * @param \Symfony\Component\Debug\Exception\FlattenException $exception
  *  The flattened exception.
  *
  * @return array
  *   An array of string-substitution tokens for formatting a message about the
  *   exception.
  */
 protected function decodeException(FlattenException $exception)
 {
     $message = $exception->getMessage();
     $backtrace = $exception->getTrace();
     // This value is missing from the stack for some reason in the
     // FlattenException version of the backtrace.
     $backtrace[0]['line'] = $exception->getLine();
     // For database errors, we try to return the initial caller,
     // skipping internal functions of the database layer.
     if (strpos($exception->getClass(), 'DatabaseExceptionWrapper') !== FALSE) {
         // A DatabaseExceptionWrapper exception is actually just a courier for
         // the original PDOException.  It's the stack trace from that exception
         // that we care about.
         $backtrace = $exception->getPrevious()->getTrace();
         $backtrace[0]['line'] = $exception->getLine();
         // 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]) && (strpos($caller['namespace'], 'Drupal\\Core\\Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE) || in_array($caller['function'], $db_functions)) {
             // We remove that call.
             array_shift($backtrace);
         }
     }
     $caller = Error::getLastCaller($backtrace);
     return array('%type' => $exception->getClass(), '!message' => String::checkPlain($message), '%function' => $caller['function'], '%file' => $caller['file'], '%line' => $caller['line'], 'severity_level' => WATCHDOG_ERROR);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:40,代码来源:ExceptionController.php


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