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


PHP FlattenException::create方法代码示例

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


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

示例1: testException

 public function testException()
 {
     $message = 'THIS IS THE ERROR MESSAGE';
     $e = new \Exception($message);
     $this->assertStringMatchesFormat("%A{$message}%A", HtmlUtilities::exception($e));
     $this->assertStringMatchesFormat("%A{$message}%A", HtmlUtilities::exception(FlattenException::create($e)));
 }
开发者ID:sitegear,项目名称:sitegear,代码行数:7,代码来源:HtmlUtilitiesTest.php

示例2: handle

 public function handle(Event $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
         return false;
     }
     $exception = $event->getParameter('exception');
     $request = $event->getParameter('request');
     if (null !== $this->logger) {
         $this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage()));
     } else {
         error_log(sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
     }
     $logger = null !== $this->logger ? $this->logger->getDebugLogger() : null;
     $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $logger, 'format' => 0 === strncasecmp(PHP_SAPI, 'cli', 3) ? 'txt' : $request->getRequestFormat());
     $request = $request->duplicate(null, null, $attributes);
     try {
         $response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
     } catch (\Exception $e) {
         if (null !== $this->logger) {
             $this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()));
         }
         // re-throw the exception as this is a catch-all
         throw new \RuntimeException('Exception thrown when handling an exception.', 0, $e);
     }
     $event->setReturnValue($response);
     return true;
 }
开发者ID:rsky,项目名称:symfony,代码行数:27,代码来源:ExceptionListener.php

示例3: testFlattenHttpException

 /**
  * @dataProvider flattenDataProvider
  */
 public function testFlattenHttpException(\Exception $exception, $statusCode)
 {
     $flattened = FlattenException::create($exception);
     $this->assertEquals($exception->getMessage(), $flattened->getMessage(), 'The message is copied from the original exception.');
     $this->assertEquals($exception->getCode(), $flattened->getCode(), 'The code is copied from the original exception.');
     $this->assertEquals(get_class($exception), $flattened->getClass(), 'The class is set to the class of the original exception');
 }
开发者ID:notbrain,项目名称:symfony,代码行数:10,代码来源:FlattenExceptionTest.php

示例4: onKernelException

 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
  */
 public function onKernelException(\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event)
 {
     if ($this->logger === null || $this->container->get('kernel')->getEnvironment() == 'dev') {
         return;
     }
     $exception = $event->getException();
     if ($exception) {
         $flattenException = \Symfony\Component\HttpKernel\Exception\FlattenException::create($exception);
         echo $this->getContent($flattenException, $clientInfo);
         exit;
         // remove if condition to send 404 error mails also
         if ($flattenException->getStatusCode() != '404') {
             $clientInfo = '<pre>' . print_r($_SERVER, true) . '</pre>';
             $message = \Swift_Message::newInstance()->setSubject($this->container->getParameter('error_email_subject'))->setFrom($this->container->getParameter('error_email_from'))->setTo($this->container->getParameter('error_email_to'))->setBody($this->decorate($this->getContent($flattenException, $clientInfo), $this->getStylesheet($flattenException)), 'text/html');
             $this->container->get('mailer')->send($message);
         }
     }
     if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
         if ('The website you are looking is either disabled or not found!' == $exception->getMessage()) {
             $response = new Response($this->container->get('twig')->render(new TemplateReference('TwigBundle', 'Exception', 'errorDisabled', 'html', 'twig'), array('status_code' => 404, 'status_text' => isset(Response::$statusTexts[404]) ? Response::$statusTexts[404] : '', 'exception' => $exception, 'logger' => null, 'currentContent' => null)));
             $event->setResponse($response);
             return;
         }
     }
 }
开发者ID:jignesh-russmediatech,项目名称:rmcdemo,代码行数:28,代码来源:ExceptionListener.php

示例5: createResponse

 /**
  * Creates the error Response associated with the given Exception.
  *
  * @param \Exception|FlattenException $exception An \Exception instance
  *
  * @return Response A Response instance
  */
 public function createResponse($exception)
 {
     $content = '';
     $title = '';
     try {
         if (!$exception instanceof FlattenException) {
             $exception = FlattenException::create($exception);
         }
         switch ($exception->getStatusCode()) {
             case 404:
                 $title = 'Sorry, the page you are looking for could not be found.';
                 break;
             default:
                 $title = 'Whoops, looks like something went wrong.';
         }
         if ($this->debug) {
             $content = $this->getContent($exception);
         }
     } catch (\Exception $e) {
         // something nasty happened and we cannot throw an exception here anymore
         if ($this->debug) {
             $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage());
         } else {
             $title = 'Whoops, looks like something went wrong.';
         }
     }
     return new Response($this->decorate($content, $title), $exception->getStatusCode());
 }
开发者ID:laubosslink,项目名称:lab,代码行数:35,代码来源:ExceptionHandler.php

示例6: createResponse

 /**
  * Creates the error Response associated with the given Exception.
  *
  * @param \Exception|FlattenException $exception An \Exception instance
  *
  * @return Response A Response instance
  */
 public function createResponse($exception)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     return new Response($this->decorate($this->getContent($exception), $this->getStylesheet($exception)), $exception->getStatusCode(), $exception->getHeaders());
 }
开发者ID:netvlies,项目名称:symfony,代码行数:14,代码来源:ExceptionHandler.php

示例7: 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:Tarendai,项目名称:spring-website,代码行数:25,代码来源:ExceptionListener.php

示例8: 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 ? FlattenException::create($ex) : null)));
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:7,代码来源:Application.php

示例9: collect

 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     if (null !== $exception) {
         $this->data = array(
             'exception' => FlattenException::create($exception),
         );
     }
 }
开发者ID:Gregwar,项目名称:symfony,代码行数:11,代码来源:ExceptionDataCollector.php

示例10: testCollect

 public function testCollect()
 {
     $e = new \Exception('foo', 500);
     $c = new ExceptionStatsCollector('prefix', $this->mockStatsDFactory('prefix.exception.500'));
     $flattened = FlattenException::create($e);
     $trace = $flattened->getTrace();
     $c->collect(new Request(), new Response(), $e);
 }
开发者ID:dainis,项目名称:StatsDClientBundle,代码行数:8,代码来源:ExceptionStatsCollectorTest.php

示例11: testRecursionInArguments

 public function testRecursionInArguments()
 {
     $a = array('foo', array(2, &$a));
     $exception = $this->createException($a);
     $flattened = FlattenException::create($exception);
     $trace = $flattened->getTrace();
     $this->assertContains('*DEEP NESTED ARRAY*', serialize($trace));
 }
开发者ID:nicodmf,项目名称:symfony,代码行数:8,代码来源:FlattenExceptionTest.php

示例12: collect

 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     if (null !== $exception) {
         $flattenException = FlattenException::create($exception);
         if ($exception instanceof HttpExceptionInterface) {
             $flattenException->setStatusCode($exception->getStatusCode());
         }
         $this->data = array('exception' => $flattenException);
     }
 }
开发者ID:artz20,项目名称:Tv-shows-zone,代码行数:13,代码来源:ExceptionDataCollector.php

示例13: testFallbackToHtmlIfNoTemplateForRequestedFormat

 public function testFallbackToHtmlIfNoTemplateForRequestedFormat()
 {
     $twig = new \Twig_Environment(new \Twig_Loader_Array(array('TwigBundle:Exception:error.html.twig' => 'html')));
     $request = Request::create('whatever');
     $request->setRequestFormat('txt');
     $exception = FlattenException::create(new \Exception());
     $controller = new ExceptionController($twig, false);
     $response = $controller->showAction($request, $exception);
     $this->assertEquals('html', $request->getRequestFormat());
 }
开发者ID:neagu-cristian,项目名称:Jobeet,代码行数:10,代码来源:ExceptionControllerTest.php

示例14: previewErrorPageAction

 public function previewErrorPageAction(Request $request, $code)
 {
     $exception = FlattenException::create(new \Exception("Something has intentionally gone wrong."), $code);
     /*
      * This Request mimics the parameters set by
      * \Symfony\Component\HttpKernel\EventListener\ExceptionListener::duplicateRequest, with
      * the additional "showException" flag.
      */
     $subRequest = $request->duplicate(null, null, array('_controller' => $this->controller, 'exception' => $exception, 'logger' => null, 'format' => $request->getRequestFormat(), 'showException' => false));
     return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
 }
开发者ID:tahermarkos,项目名称:Transport,代码行数:11,代码来源:PreviewErrorController.php

示例15: handle

    /**
     * Returns a Response for the given Exception.
     *
     * @param \Exception $exception An \Exception instance
     *
     * @return Response A Response instance
     */
    public function handle(\Exception $exception)
    {
        try {
            $exception = FlattenException::create($exception);

            $response = new Response($this->decorate($exception, $this->getContent($exception)), 500);

            $response->send();
        } catch (\Exception $e) {
            // something nasty happened and we cannot throw an exception here anymore
            printf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage());
        }
    }
开发者ID:regisg27,项目名称:symfony,代码行数:20,代码来源:ExceptionHandler.php


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