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


PHP GetResponseForExceptionEvent::getResponse方法代码示例

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


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

示例1: onException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onException(GetResponseForExceptionEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $this->eventDispatcher->dispatch(Events::REQUEST_ENDS, new RequestEnded($event->getRequest(), $event->getResponse(), $event->getException()));
 }
开发者ID:Tolerance,项目名称:Tolerance,代码行数:10,代码来源:DispatchRequestEndedEvent.php

示例2: assertResponse

 protected function assertResponse(GetResponseForExceptionEvent $event, $content, $code)
 {
     $response = $event->getResponse();
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertSame($content, $response->getContent());
     $this->assertSame($code, $response->getStatusCode());
 }
开发者ID:glynnforrest,项目名称:neptune,代码行数:7,代码来源:TwigExceptionListenerTest.php

示例3: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($event->getResponse() !== null) {
         return;
     }
     $exception = $event->getException();
     if (!$exception instanceof OAuthException) {
         return;
     }
     $response = new JsonResponse(["code" => $exception->getCode(), "error" => $exception->getMessage()]);
     $event->setResponse($response);
 }
开发者ID:koenreiniers,项目名称:oauth-server-bundle,代码行数:15,代码来源:ExceptionListener.php

示例4: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $statusCode = $this->getHttpStatusCode($exception->getCode());
     if ($this->application->isDebugMode()) {
         $this->response = $this->getDebugTraceResponse($exception, $statusCode);
     } else {
         $this->response = $this->getErrorPageResponse($exception, $statusCode);
     }
     $event->setResponse($this->response);
     $filterEvent = new FilterResponseEvent($event->getKernel(), $event->getRequest(), $event->getRequestType(), $event->getResponse());
     $event->getDispatcher()->dispatch(KernelEvents::RESPONSE, $filterEvent);
 }
开发者ID:backbee,项目名称:backbee,代码行数:16,代码来源:ExceptionListener.php

示例5: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (false == $event->getException() instanceof InteractiveRequestInterface) {
         return;
     }
     $interactiveRequest = $event->getException();
     if ($interactiveRequest instanceof SymfonyResponseInteractiveRequest) {
         $event->setResponse($interactiveRequest->getResponse());
     } elseif ($interactiveRequest instanceof ResponseInteractiveRequest) {
         $event->setResponse(new Response($interactiveRequest->getContent()));
     } elseif ($interactiveRequest instanceof RedirectUrlInteractiveRequest) {
         $event->setResponse(new RedirectResponse($interactiveRequest->getUrl()));
     }
     if ($event->getResponse()) {
         if (false == $event->getResponse()->headers->has('X-Status-Code')) {
             $event->getResponse()->headers->set('X-Status-Code', $event->getResponse()->getStatusCode());
         }
         return;
     }
     $ro = new \ReflectionObject($interactiveRequest);
     $event->setException(new LogicException(sprintf('Cannot convert interactive request %s to symfony response.', $ro->getShortName()), null, $interactiveRequest));
 }
开发者ID:sanchojaf,项目名称:oldmytriptocuba,代码行数:25,代码来源:InteractiveRequestListener.php

示例6: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  **/
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ('html' === $this->responseFormat) {
         return;
     }
     $exception = $event->getException();
     $response = $event->getResponse();
     $response->setContent($this->serializer->serialize($exception->getMessage(), array(), $this->responseFormat));
     if ($exception instanceof HttpExceptionInterface) {
         $response->setStatusCode($exception->getStatusCode());
         $response->headers->replace($exception->getHeaders());
     } else {
         $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
     }
 }
开发者ID:ihsanudin,项目名称:males-bundle,代码行数:18,代码来源:ResponseFormatListener.php

示例7: onKernelException

 /**
  * Handles a kernel exception and returns a relevant response.
  * Aims to deliver content to the user that explains the exception, rather than falling
  * back on symfony's exception handler which displays a less verbose error message.
  *
  * @param GetResponseForExceptionEvent $event The exception event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     // do nothing if request is no preview request
     if (!$event->getRequest()->get('preview', false)) {
         return;
     }
     $ex = $event->getException();
     $code = 500;
     $previousContent = $event->getResponse();
     $content = $previousContent !== null ? $previousContent->getContent() : '';
     $statusTexts = Response::$statusTexts;
     $statusText = isset($statusTexts[$code]) ? $statusTexts[$code] : '';
     $exception = FlattenException::create($ex, $code);
     // log exception
     $this->logger->error(sprintf('%s (%s %s)', $ex->getMessage(), $code, $statusText));
     $responseContent = $this->templateEngine->render($this->findTemplate(), ['status_code' => $code, 'status_text' => $statusText, 'exception' => $exception, 'logger' => null, 'currentContent' => $content]);
     $event->setResponse(new Response($responseContent));
 }
开发者ID:Silwereth,项目名称:sulu,代码行数:25,代码来源:PreviewExceptionListener.php

示例8: logrefInResponseAndLogMatch

 /**
  * @test
  */
 public function logrefInResponseAndLogMatch()
 {
     foreach ([400, 500] as $code) {
         $logref = null;
         $logger = $this->getMockForAbstractClass('Psr\\Log\\LoggerInterface');
         $logger->expects($this->once())->method($this->anything())->with($this->callback(function ($message) use(&$logref) {
             $matches = [];
             if (preg_match('/logref ([a-z0-9]*)/', $message, $matches)) {
                 $logref = $matches[1];
                 return true;
             }
             return false;
         }));
         /** @var LoggerInterface $logger */
         $this->exceptionListener->setLogger($logger);
         $this->codeProperty->setValue($this->exception, $code);
         $this->exceptionListener->onKernelException($this->event);
         $response = $this->event->getResponse();
         $this->assertEquals($logref, json_decode($response->getContent())->logref);
     }
 }
开发者ID:krizon,项目名称:swagger-bundle,代码行数:24,代码来源:ExceptionListenerTest.php

示例9: getValidationFailedExceptionResponse

 /**
  * Get correct response for validation failed exception
  *
  * @param GetResponseForExceptionEvent $event           event
  * @param EventDispatcherInterface     $eventDispatcher eventDispatcher
  * @param ValidationFailedException    $exception       exception
  *
  * @return Response|null
  */
 private function getValidationFailedExceptionResponse(GetResponseForExceptionEvent $event, EventDispatcherInterface $eventDispatcher, ValidationFailedException $exception)
 {
     $event->stopPropagation();
     $request = $event->getRequest();
     $transaction = $request->get('transaction');
     if (!$transaction) {
         return $event->getResponse();
     }
     $data = $request->get($request->get(Alias::DATA));
     $violations = $exception->getConstraintViolationList();
     $request->attributes->set('violations', $violations);
     $view = View::create($data);
     $responseEvent = new GetResponseForControllerResultEvent($event->getKernel(), $request, $request->getMethod(), $view);
     if ($view->getData() instanceof ArrayCollection) {
         $responseEvent->getRequest()->attributes->set(EmbeddedManager::KEY_EMBED, EmbeddedManager::GROUP_VIOLATION_COLLECTION);
     } else {
         $responseEvent->getRequest()->attributes->set(EmbeddedManager::KEY_EMBED, EmbeddedManager::GROUP_VIOLATION_ENTITY);
     }
     $eventDispatcher->dispatch('kernel.view', $responseEvent);
     return $responseEvent->getResponse();
 }
开发者ID:RomanShumkov,项目名称:EcentriaRestBundle,代码行数:30,代码来源:ExceptionListener.php

示例10: getValidationFailedExceptionResponse

 /**
  * Get correct response for validation failed exception
  *
  * @param GetResponseForExceptionEvent $event           event
  * @param EventDispatcherInterface     $eventDispatcher eventDispatcher
  * @param ValidationFailedException    $exception       exception
  *
  * @return Response|null
  */
 private function getValidationFailedExceptionResponse(GetResponseForExceptionEvent $event, EventDispatcherInterface $eventDispatcher, ValidationFailedException $exception)
 {
     $event->stopPropagation();
     $request = $event->getRequest();
     $transaction = $request->get('transaction');
     if (!$transaction) {
         return $event->getResponse();
     }
     $data = $request->get($request->get(Alias::DATA));
     $violations = $exception->getConstraintViolationList();
     $request->attributes->set('violations', $violations);
     $view = View::create($data);
     $responseEvent = new GetResponseForControllerResultEvent($event->getKernel(), $request, $request->getMethod(), $view);
     $eventDispatcher->dispatch('kernel.view', $responseEvent);
     $responseData = $view->getData();
     if ($responseData instanceof EmbeddedInterface) {
         $responseData->setShowAssociations(true);
     }
     if ($responseData instanceof CollectionResponse) {
         $responseData->setInheritedShowAssociations(false);
     }
     return $responseEvent->getResponse();
 }
开发者ID:RuslanZavacky,项目名称:EcentriaRestBundle,代码行数:32,代码来源:ExceptionListener.php

示例11: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $statusCode = $exception->getCode();
     if ($this->application->isDebugMode()) {
         $this->response = (new \Symfony\Component\Debug\ExceptionHandler())->createResponse($exception);
     }
     if (!$this->application->isDebugMode()) {
         switch ($statusCode) {
             case 404:
             case 500:
                 $parameterKey = "error.{$statusCode}";
                 break;
             default:
                 $parameterKey = 'error.default';
         }
         $parameter = $this->application->getContainer()->getParameter($parameterKey);
         $view = $this->getErrorTemplate($parameter);
         $this->response->setStatusCode($statusCode)->setContent($this->renderer->partial($view, ['error' => $exception]));
     }
     $event->setResponse($this->response);
     $filterEvent = new FilterResponseEvent($event->getKernel(), $event->getRequest(), $event->getRequestType(), $event->getResponse());
     $event->getDispatcher()->dispatch(KernelEvents::RESPONSE, $filterEvent);
 }
开发者ID:nietzcheson,项目名称:BackBee,代码行数:24,代码来源:ExceptionListener.php

示例12: setNewResponse

 /**
  * Sets a new response to $event
  * @param GetResponseForExceptionEvent $event   The event
  * @param int $statusCode                       The status code of the new response
  * @param string $message                       Optional, the message of the new response
  */
 private function setNewResponse(GetResponseForExceptionEvent $event, $statusCode, $message = '')
 {
     $event->setResponse(new Response());
     $event->getResponse()->setStatusCode($statusCode, $message);
 }
开发者ID:Bensid,项目名称:BackBee,代码行数:11,代码来源:ExceptionListener.php

示例13: onException

 public function onException(GetResponseForExceptionEvent $event)
 {
     $key = $this->getRequestKey($event->getRequest());
     $this->errors++;
     $this->calls[$key] = array_merge($this->calls[$key], array('response' => $event->getResponse(), "error" => $event->getException(), "stop" => microtime(true)));
     $this->finishEvent($key);
 }
开发者ID:bogeux,项目名称:SimpleHttpBundle,代码行数:7,代码来源:ProfilerDataCollector.php


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