本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent::isMasterRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseForExceptionEvent::isMasterRequest方法的具体用法?PHP GetResponseForExceptionEvent::isMasterRequest怎么用?PHP GetResponseForExceptionEvent::isMasterRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
的用法示例。
在下文中一共展示了GetResponseForExceptionEvent::isMasterRequest方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onKernelException
/**
* Map an exception to an error screen.
*
* @param GetResponseForExceptionEvent $event The event object
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$event->isMasterRequest() || 'html' !== $event->getRequest()->getRequestFormat()) {
return;
}
$this->handleException($event);
}
示例2: onKernelException
/**
* Handles the onKernelException event.
*
* @param GetResponseForExceptionEvent $event A GetResponseForExceptionEvent instance
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ($this->onlyMasterRequests && !$event->isMasterRequest()) {
return;
}
$this->exception = $event->getException();
}
示例3: 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()));
}
示例4: onKernelException
/**
* Log de l'erreur dans MongoDB
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
// don't do anything if it's not the master request
if (!$event->isMasterRequest()) {
return;
}
// Create logs
try {
$log = new ErrorLog();
$exception = $event->getException();
$request = $event->getRequest();
// Current User
if ($this->securityContext->getToken() && $this->securityContext->isGranted('ROLE_USER')) {
$log->setUsername($this->securityContext->getToken()->getUser()->getUsername());
$log->setUserid($this->securityContext->getToken()->getUser()->getId());
} else {
$log->setUsername(null);
}
// Get error code
if (method_exists($exception, 'getStatusCode')) {
$log->setCode($exception->getStatusCode());
} else {
$log->setCode($exception->getCode());
}
$log->setMessage($exception->getMessage());
$log->setUrl($request->getUri());
$log->setIp($request->getClientIp());
$log->setReferer($request->headers->get('referer'));
if (in_array($log->getCode(), array('0', '404', '500'))) {
$this->em->persist($log);
$this->em->flush();
}
} catch (\Exception $e) {
}
}
示例5: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$exception = $event->getException();
if ($exception instanceof HttpException) {
$status = $exception->getStatusCode();
$headers = $exception->getHeaders();
} elseif ($exception instanceof DeserializationException) {
$status = Response::HTTP_BAD_REQUEST;
$headers = [];
} else {
$code = method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : $exception->getCode();
$status = isset(Response::$statusTexts[$code]) ? $code : Response::HTTP_BAD_REQUEST;
$headers = [];
}
// Normalize exceptions with hydra errors only for resources
if ($request->attributes->has('_resource')) {
$dataResponse = $this->serializer->serialize($exception, $this->format);
$response = new Response($dataResponse, $status, $headers);
if ($this->format === 'xml') {
$response = new XmlResponse($dataResponse, $status, $headers);
}
$event->setResponse($response);
}
}
示例6: onKernelException
public function onKernelException(GetResponseForExceptionEvent $event)
{
$this->logger->notice(sprintf('Exceptions catcher listener: catch kernel.exception event (exception: %s)', $event->getException()->getMessage()));
// If this is not a master request, skip handling
if (!$event->isMasterRequest()) {
$this->logger->debug('Exceptions catcher listener: this is not master request, skip');
return;
}
// If content already prepared
if ($event->hasResponse()) {
$this->logger->debug('Exceptions catcher listener: event already has response, skip');
return;
}
// Getting action
$apiServerAction = $event->getRequest()->attributes->get('apiAction');
/* @var $apiServerAction ApiServerAction */
// Something wrong
if (!$apiServerAction) {
$this->logger->error('Request parser listener: request has no apiAction attribute, sending empty response');
$event->setResponse(new JsonResponse([]));
return;
}
// Getting api server interface
$apiServerInterface = $apiServerAction->getApiServerInterface();
// Creating api response
$apiResponse = $apiServerInterface->getExceptionResponse($event->getException()->getMessage());
// Setting response
$event->setResponse(new JsonResponse($apiResponse->export()));
}
示例7: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
if (!$request->attributes->has('_resource_type') || self::FORMAT !== $request->attributes->get('_api_format')) {
return;
}
$exception = $event->getException();
$headers = [];
if ($exception instanceof HttpException) {
$status = $exception->getStatusCode();
$headers = $exception->getHeaders();
$data = $exception;
} elseif ($exception instanceof ValidationException) {
$status = Response::HTTP_BAD_REQUEST;
$data = $exception->getConstraintViolationList();
} elseif ($exception instanceof ExceptionInterface || $exception instanceof InvalidArgumentException) {
$status = Response::HTTP_BAD_REQUEST;
$data = $exception;
} else {
$status = Response::HTTP_INTERNAL_SERVER_ERROR;
$data = $exception;
}
$event->setResponse(new Response($this->normalizer->normalize($data, 'hydra-error'), $status, $headers));
}
示例8: onException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onException(GetResponseForExceptionEvent $event)
{
if (!$event->getException() instanceof NotFoundHttpException) {
return;
}
if (!$event->isMasterRequest()) {
return;
}
if (!($redirect = $this->getRedirectForRequest($event->getRequest()))) {
return;
}
$event->setResponse($redirect);
}
示例9: onKernelException
/**
* Kernel exception listener callback.
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$app = $this->app;
if (!$app->isTestMode()) {
if ($app['orm.em']->getConnection()->isTransactionActive()) {
$app['orm.em']->rollback();
}
} else {
$this->app->log('TestCase to onKernelException of rollback');
}
}
示例10: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$exception = $event->getException();
if ($exception instanceof HttpException) {
$status = $exception->getStatusCode();
$headers = $exception->getHeaders();
} elseif ($exception instanceof DeserializationException) {
$status = Response::HTTP_BAD_REQUEST;
$headers = [];
} else {
$status = Response::HTTP_INTERNAL_SERVER_ERROR;
$headers = [];
}
// Normalize exceptions with hydra errors only for resources
if ($request->attributes->has('_resource')) {
$event->setResponse(new Response($this->normalizer->normalize($exception, 'hydra-error'), $status, $headers));
}
}
示例11: onKernelException
/**
*
* @author Krzysztof Bednarczyk
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$exception = $event->getException();
$isXVRequest = (int) $event->getRequest()->headers->get('X-XV-Request', 0);
if ($exception instanceof AccessDeniedHttpException || $exception instanceof AccessDeniedHttpException || $exception instanceof AuthenticationException) {
$path = parse_url($event->getRequest()->getRequestUri(), PHP_URL_PATH);
$event->setResponse(new RedirectResponse("/login/?r={$path}"));
$event->stopPropagation();
return;
}
if ($exception instanceof NotFoundHttpException) {
$event->setResponse(new RedirectResponse("/page/404/" . ($isXVRequest ? "?dialog=true" : "")));
$event->stopPropagation();
return;
}
if ($exception instanceof CsrfHttpException) {
$event->setResponse(new RedirectResponse("/page/csrf/"));
$event->stopPropagation();
return;
}
}