本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent::getDispatcher方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseForExceptionEvent::getDispatcher方法的具体用法?PHP GetResponseForExceptionEvent::getDispatcher怎么用?PHP GetResponseForExceptionEvent::getDispatcher使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
的用法示例。
在下文中一共展示了GetResponseForExceptionEvent::getDispatcher方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
/** @var \appProdProjectContainer $container */
if ($exception instanceof \SoapFault) {
$container = $event->getDispatcher()->getContainer();
$errorResponse = $container->get('med_coupon_service.transport.med_coupon_service_transport_api')->getTalonClientSOAP()->getCurl()->getResponse();
// $container->get('med_coupon_service.transport.med_coupon_service_transport_api');
$server = new Server();
$response = $server->getResponse(array('error' => array('code' => $exception->getCode(), 'message' => $exception->getMessage(), 'data' => $errorResponse)), array('id' => null));
// $response = new Response('<error>1<error>');
echo $response;
exit;
}
}
示例3: onKernelException
/**
* Handles security related exceptions.
*
* @param GetResponseForExceptionEvent $event An GetResponseForExceptionEvent instance
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
// we need to remove ourselves as the exception listener can be
// different depending on the Request
$event->getDispatcher()->removeListener(KernelEvents::EXCEPTION, array($this, 'onKernelException'));
$exception = $event->getException();
do {
if ($exception instanceof AuthenticationException) {
return $this->handleAuthenticationException($event, $exception);
} elseif ($exception instanceof AccessDeniedException) {
return $this->handleAccessDeniedException($event, $exception);
} elseif ($exception instanceof LogoutException) {
return $this->handleLogoutException($event, $exception);
}
} while (null !== ($exception = $exception->getPrevious()));
}
示例4: 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);
}
示例5: onKernelException
/**
* Handles security related exceptions.
*
* @param GetResponseForExceptionEvent $event An GetResponseForExceptionEvent instance
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
// we need to remove ourselves as the exception listener can be
// different depending on the Request
$event->getDispatcher()->removeListener(KernelEvents::EXCEPTION, array($this, 'onKernelException'));
$exception = $event->getException();
$request = $event->getRequest();
// determine the actual cause for the exception
while (null !== ($previous = $exception->getPrevious())) {
$exception = $previous;
}
if ($exception instanceof AuthenticationException) {
if (null !== $this->logger) {
$this->logger->info(sprintf('Authentication exception occurred; redirecting to authentication entry point (%s)', $exception->getMessage()));
}
try {
$response = $this->startAuthentication($request, $exception);
} catch (\Exception $e) {
$event->setException($e);
return;
}
} elseif ($exception instanceof AccessDeniedException) {
$event->setException(new AccessDeniedHttpException($exception->getMessage(), $exception));
$token = $this->context->getToken();
if (!$this->authenticationTrustResolver->isFullFledged($token)) {
if (null !== $this->logger) {
$this->logger->debug(sprintf('Access is denied (user is not fully authenticated) by "%s" at line %s; redirecting to authentication entry point', $exception->getFile(), $exception->getLine()));
}
try {
$insufficientAuthenticationException = new InsufficientAuthenticationException('Full authentication is required to access this resource.', 0, $exception);
$insufficientAuthenticationException->setToken($token);
$response = $this->startAuthentication($request, $insufficientAuthenticationException);
} catch (\Exception $e) {
$event->setException($e);
return;
}
} else {
if (null !== $this->logger) {
$this->logger->debug(sprintf('Access is denied (and user is neither anonymous, nor remember-me) by "%s" at line %s', $exception->getFile(), $exception->getLine()));
}
try {
if (null !== $this->accessDeniedHandler) {
$response = $this->accessDeniedHandler->handle($request, $exception);
if (!$response instanceof Response) {
return;
}
} elseif (null !== $this->errorPage) {
$subRequest = $this->httpUtils->createRequest($request, $this->errorPage);
$subRequest->attributes->set(SecurityContextInterface::ACCESS_DENIED_ERROR, $exception);
$response = $event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
} else {
return;
}
} catch (\Exception $e) {
if (null !== $this->logger) {
$this->logger->error(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()));
}
$event->setException(new \RuntimeException('Exception thrown when handling an exception.', 0, $e));
return;
}
}
} elseif ($exception instanceof LogoutException) {
if (null !== $this->logger) {
$this->logger->info(sprintf('Logout exception occurred; wrapping with AccessDeniedHttpException (%s)', $exception->getMessage()));
}
return;
} else {
return;
}
$event->setResponse($response);
}