Symfony\Component\Debug\Exception\FlattenException::create PHP Méthode

create() public static méthode

public static create ( Exception $exception, $statusCode = null, array $headers = [] )
$exception Exception
$headers array
    public static function create(\Exception $exception, $statusCode = null, array $headers = array())
    {
        $e = new static();
        $e->setMessage($exception->getMessage());
        $e->setCode($exception->getCode());

        if ($exception instanceof HttpExceptionInterface) {
            $statusCode = $exception->getStatusCode();
            $headers = array_merge($headers, $exception->getHeaders());
        } elseif ($exception instanceof RequestExceptionInterface) {
            $statusCode = 400;
        }

        if (null === $statusCode) {
            $statusCode = 500;
        }

        $e->setStatusCode($statusCode);
        $e->setHeaders($headers);
        $e->setTraceFromException($exception);
        $e->setClass(get_class($exception));
        $e->setFile($exception->getFile());
        $e->setLine($exception->getLine());

        $previous = $exception->getPrevious();

        if ($previous instanceof \Exception) {
            $e->setPrevious(static::create($previous));
        } elseif ($previous instanceof \Throwable) {
            $e->setPrevious(static::create(new FatalThrowableError($previous)));
        }

        return $e;
    }

Usage Example

Exemple #1
0
 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();
     }
 }
All Usage Examples Of Symfony\Component\Debug\Exception\FlattenException::create