本文整理汇总了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)));
}
示例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;
}
示例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');
}
示例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;
}
}
}
示例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());
}
示例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());
}
示例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;
}
示例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)));
}
示例9: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
if (null !== $exception) {
$this->data = array(
'exception' => FlattenException::create($exception),
);
}
}
示例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);
}
示例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));
}
示例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);
}
}
示例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());
}
示例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);
}
示例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());
}
}