コード例 #1
0
ファイル: LoggerHandler.php プロジェクト: hhamon/lpdim2016
 public function onKernelException(ExceptionEvent $event)
 {
     $exception = $event->getException();
     $message = $exception->getMessage();
     if ($exception instanceof HttpNotFoundException) {
         return $this->logger->error($message);
     }
     if ($exception instanceof RouteNotFoundException) {
         return $this->logger->error($message);
     }
     if ($exception instanceof MethodNotAllowedException) {
         return $this->logger->error($message);
     }
     $this->logger->critical($message);
 }
コード例 #2
0
 public function testStopExceptionEvent()
 {
     $request = new Request('GET', '/home', 'HTTP', '1.1');
     $response = Response::createFromRequest($request, '', 200);
     $exception = new \Exception();
     $event = new ExceptionEvent($exception, $request);
     $this->assertSame($exception, $event->getException());
     $this->assertSame($request, $event->getRequest());
     $this->assertNull($event->getResponse());
     $this->assertFalse($event->hasResponse());
     $this->assertFalse($event->isStopped());
     $event->setResponse($response);
     $this->assertTrue($event->hasResponse());
     $this->assertSame($response, $event->getResponse());
     $this->assertTrue($event->isStopped());
 }
コード例 #3
0
ファイル: ErrorHandler.php プロジェクト: hhamon/lpdim2016
 public function onKernelException(ExceptionEvent $event)
 {
     $exception = $event->getException();
     $request = $event->getRequest();
     $vars = ['exception' => $exception, 'request' => $request, 'environment' => $this->environment, 'debug' => $this->debug];
     if ($exception instanceof RouteNotFoundException) {
         $event->setResponse($this->render('errors/404.twig', $vars, Response::HTTP_NOT_FOUND));
         return;
     }
     if ($exception instanceof HttpNotFoundException) {
         $event->setResponse($this->render('errors/404.twig', $vars, Response::HTTP_NOT_FOUND));
         return;
     }
     if ($exception instanceof MethodNotAllowedException) {
         $event->setResponse($this->render('errors/405.twig', $vars, Response::HTTP_METHOD_NOT_ALLOWED));
         return;
     }
     $event->setResponse($this->render('errors/500.twig', $vars));
 }