當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FlattenException::create方法代碼示例

本文整理匯總了PHP中Symfony\Component\Debug\Exception\FlattenException::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP FlattenException::create方法的具體用法?PHP FlattenException::create怎麽用?PHP FlattenException::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Debug\Exception\FlattenException的用法示例。


在下文中一共展示了FlattenException::create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: sendMail

 public function sendMail(\Exception $exception, Request $request, array $context, $needToFlush)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     if (!$this->_hasInitialized) {
         $this->_initialize();
     }
     $params = array('exception' => $exception, 'request' => $request, 'context' => $context, 'status_text' => Response::$statusTexts[$exception->getStatusCode()]);
     $preMailEvent = new GenericEvent($params, array('shouldSend' => true));
     $this->_eventDispatcher->dispatch('ehough.bundle.emailErrors.preMail', $preMailEvent);
     if (!$preMailEvent->getArgument('shouldSend')) {
         //mail was cancelled
         return;
     }
     $body = $this->_templatingEngine->render('EhoughEmailErrorsBundle::mail.html.twig', $params);
     $subject = '[' . $request->headers->get('host') . '] Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage();
     if (function_exists('mb_substr')) {
         $subject = mb_substr($subject, 0, 255);
     } else {
         $subject = substr($subject, 0, 255);
     }
     $mail = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->_fromAddress)->setTo($this->_toAddress)->setContentType('text/html')->setBody($body);
     $this->_mailer->send($mail);
     if ($needToFlush) {
         $this->_flushEmailer();
     }
 }
開發者ID:ehough,項目名稱:emailerrors-bundle,代碼行數:28,代碼來源:Mailer.php

示例2: duplicateRequest

 /**
  * Clones the request for the exception.
  *
  * @param \Exception $exception
  * @param  Request   $request
  * @return Request   $request
  */
 protected function duplicateRequest(\Exception $exception, Request $request)
 {
     $attributes = ['_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger];
     $request = $request->duplicate(null, null, $attributes);
     $request->setMethod('GET');
     return $request;
 }
開發者ID:LibraryOfLawrence,項目名稱:pagekit,代碼行數:14,代碼來源:ExceptionListener.php

示例3: sendException

 public function sendException($exception)
 {
     if (!$this->isErrorFromBot()) {
         $recipients = Config::get("error-emailer::to");
         if (isset($recipients['address'])) {
             // this is a single recipient
             if ($recipients['address']) {
                 $recipients = array($recipients);
             } else {
                 $recipients = array();
             }
         }
         if (sizeof($recipients) > 0) {
             if ($exception instanceof FlattenException) {
                 $flattened = $exception;
             } else {
                 $flattened = FlattenException::create($exception);
             }
             $handler = new ExceptionHandler();
             $content = $handler->getContent($flattened);
             $model = array('trace' => $content, 'exception' => $exception, 'flattened' => $flattened);
             Mail::send(Config::get("error-emailer::error_template"), $model, function ($message) use($model, $recipients) {
                 $subject = View::make(Config::get("error-emailer::subject_template"), $model)->render();
                 $message->subject($subject);
                 foreach ($recipients as $to) {
                     $message->to($to['address'], $to['name']);
                 }
             });
         }
     }
 }
開發者ID:Nuwira,項目名稱:laravel-error-emailer,代碼行數:31,代碼來源:ErrorEmailer.php

示例4: convertExceptionToResponse

 protected function convertExceptionToResponse(Exception $e)
 {
     $e = FlattenException::create($e);
     $handler = new KommerceExceptionHandler(config('app.debug'));
     $decorated = $this->decorate($handler->getContent($e), $handler->getStylesheet($e));
     return SymfonyResponse::create($decorated, $e->getStatusCode(), $e->getHeaders());
 }
開發者ID:inklabs,項目名稱:kommerce-laravel,代碼行數:7,代碼來源:Handler.php

示例5: render

 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     switch (get_class($e)) {
         case "Swift_TransportException":
         case "PDOException":
             $errorView = "errors.500_config";
             break;
         case "ErrorException":
             $errorView = "errors.500";
             break;
         case "Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException":
             return abort(400);
         default:
             $errorView = false;
             break;
     }
     if ($errorView) {
         // This makes use of a Symfony error handler to make pretty traces.
         $SymfonyDisplayer = new SymfonyDisplayer(config('app.debug'));
         $FlattenException = FlattenException::create($e);
         $SymfonyCss = $SymfonyDisplayer->getStylesheet($FlattenException);
         $SymfonyHtml = $SymfonyDisplayer->getContent($FlattenException);
         $response = response()->view($errorView, ['exception' => $e, 'error_class' => get_class($e), 'error_css' => $SymfonyCss, 'error_html' => $SymfonyHtml], 500);
         return $this->toIlluminateResponse($response, $e);
     } else {
         return parent::render($request, $e);
     }
 }
開發者ID:RustyGamer,項目名稱:infinity-next,代碼行數:35,代碼來源:Handler.php

示例6: createResponse

 /**
  * {@inheritdoc}
  */
 public function createResponse($exception)
 {
     if ($exception instanceof HttpException) {
         $exception = FlattenException::create($exception, $exception->getCode());
     }
     return parent::createResponse($exception);
 }
開發者ID:pagekit,項目名稱:pagekit,代碼行數:10,代碼來源:ExceptionHandler.php

示例7: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $request = $event->getRequest();
     $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
     $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, 'format' => $request->getRequestFormat());
     $request = $request->duplicate(null, null, $attributes);
     $request->setMethod('GET');
     try {
         $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
     } catch (\Exception $e) {
         $this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), false);
         $wrapper = $e;
         while ($prev = $wrapper->getPrevious()) {
             if ($exception === ($wrapper = $prev)) {
                 throw $e;
             }
         }
         $prev = new \ReflectionProperty('Exception', 'previous');
         $prev->setAccessible(true);
         $prev->setValue($wrapper, $exception);
         throw $e;
     }
     $event->setResponse($response);
 }
開發者ID:ccq18,項目名稱:EduSoho,代碼行數:25,代碼來源:ExceptionListener.php

示例8: handleKernelException

 public function handleKernelException(GetResponseForExceptionEvent $event)
 {
     if ($this->container->get('kernel')->getEnvironment() !== 'dev') {
         $exception = FlattenException::create($event->getException());
         // First, log the exception to the standard error logs.
         $this->container->get('logger')->error(' In File ' . $exception->getFile() . ', on line ' . $exception->getLine() . ': ' . $exception->getMessage());
         // Determine what the HTTP status code should be.
         if ($event->getException() instanceof \Symfony\Component\HttpKernel\Exception\HttpException) {
             $httpStatusCode = $event->getException()->getStatusCode();
         } else {
             $httpStatusCode = $exception->getCode();
             if ($exception->getCode() < 100 || $exception->getCode() >= 600) {
                 $httpStatusCode = 500;
             }
         }
         $parameters = ['status_code' => $httpStatusCode, 'status_text' => $exception->getMessage(), 'exception' => $exception];
         if (in_array('application/json', $event->getRequest()->getAcceptableContentTypes())) {
             $errorContent = $this->container->get('templating')->render(':default:exception.json.twig', $parameters);
         } else {
             $errorContent = $this->container->get('templating')->render(':default:error.html.twig', $parameters);
         }
         $response = new Response($errorContent, $httpStatusCode);
         $response->setProtocolVersion('1.1');
         $event->setResponse($response);
     }
 }
開發者ID:belackriv,項目名稱:step-inventory,代碼行數:26,代碼來源:ExceptionEventListener.php

示例9: saveDebugInformation

 private function saveDebugInformation(\Exception $ex = null)
 {
     if (!$this->input->hasOption('jms-job-id') || null === ($jobId = $this->input->getOption('jms-job-id'))) {
         return;
     }
     $this->getConnection()->executeUpdate("UPDATE jms_jobs SET stackTrace = :trace, memoryUsage = :memoryUsage, memoryUsageReal = :memoryUsageReal WHERE id = :id", array('id' => $jobId, 'memoryUsage' => memory_get_peak_usage(), 'memoryUsageReal' => memory_get_peak_usage(true), 'trace' => serialize($ex ? class_exists(FlattenException::class) ? FlattenException::create($ex) : LegacyFlattenException::create($ex) : null)), array('id' => \PDO::PARAM_INT, 'memoryUsage' => \PDO::PARAM_INT, 'memoryUsageReal' => \PDO::PARAM_INT, 'trace' => \PDO::PARAM_LOB));
 }
開發者ID:psylosss,項目名稱:JMSJobQueueBundle,代碼行數:7,代碼來源:Application.php

示例10: createResponse

 public function createResponse($exception, $onlyHtmlBodyContent = false)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     return Response::create($this->render($exception, $onlyHtmlBodyContent), $exception->getStatusCode(), $exception->getHeaders())->setCharset($this->charset);
 }
開發者ID:swayok,項目名稱:laravel-extended-errors,代碼行數:7,代碼來源:ExceptionRenderer.php

示例11: render

 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function render($request, Exception $e)
 {
     $e = FlattenException::create($e);
     $handler = new SymfonyExceptionHandler(env('APP_DEBUG', false));
     $decorated = $this->decorate($handler->getContent($e), $handler->getStylesheet($e));
     return Response::create($decorated, $e->getStatusCode(), $e->getHeaders());
 }
開發者ID:rlacerda83,項目名稱:lumen-framework,代碼行數:14,代碼來源:Handler.php

示例12: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $flattenException = FlattenException::create($exception);
     $msg = 'Something went wrong! (' . $flattenException->getMessage() . ')';
     $event->setResponse(new Response($msg, $flattenException->getStatusCode()));
 }
開發者ID:voxsim,項目名稱:minima,代碼行數:7,代碼來源:ExceptionListener.php

示例13: createApplication

 public function createApplication()
 {
     $app = new ApplicationTest();
     $app['route_class'] = 'Euskadi31\\Silex\\Controller\\RouteTest';
     $app['debug'] = true;
     //unset($app['exception_handler']);
     $app->mount('/', new AuthorizeControllerProvider());
     $app->error(function (Exception $exception, $code) use($app) {
         $e = FlattenException::create($exception);
         $headers = [];
         if ($exception instanceof HttpExceptionInterface) {
             $headers = $exception->getHeaders();
             $code = $exception->getStatusCode();
         } else {
             $code = $exception->getCode();
         }
         if ($code < 100 || $code >= 600) {
             $code = 500;
         }
         $error = ['error' => ['message' => $exception->getMessage(), 'type' => join('', array_slice(explode('\\', get_class($exception)), -1)), 'code' => $code]];
         if ($this->app['debug']) {
             $error['error']['exception'] = $e->toArray();
         }
         return new Response($app->json($error, $code, $headers));
     });
     return $app;
 }
開發者ID:euskadi31,項目名稱:OAuth2ServerServiceProvider,代碼行數:27,代碼來源:AuthorizeControllerProviderTest.php

示例14: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     static $handling;
     if (true === $handling) {
         return false;
     }
     $handling = true;
     $exception = $event->getException();
     $request = $event->getRequest();
     $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
     $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, 'format' => $request->getRequestFormat());
     $request = $request->duplicate(null, null, $attributes);
     $request->setMethod('GET');
     try {
         $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
     } catch (\Exception $e) {
         $this->logException($exception, sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()), false);
         // set handling to false otherwise it wont be able to handle further more
         $handling = false;
         // re-throw the exception from within HttpKernel as this is a catch-all
         return;
     }
     $event->setResponse($response);
     $handling = false;
 }
開發者ID:llinder,項目名稱:FrameworkBenchmarks,代碼行數:25,代碼來源:ExceptionListener.php

示例15: handleWithSymfony

 protected function handleWithSymfony(Exception $exception)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     $handler = new ExceptionHandler($this->debug);
     return Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders());
 }
開發者ID:autarky,項目名稱:framework,代碼行數:8,代碼來源:DefaultErrorHandler.php


注:本文中的Symfony\Component\Debug\Exception\FlattenException::create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。