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


PHP GetResponseForExceptionEvent::getKernel方法代码示例

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


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

示例1: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $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, false);
     } catch (\Exception $e) {
         $this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), false);
         $wrapper = $e;
         while ($prev = $wrapper->getPrevious()) {
             if ($exception === ($wrapper = $prev)) {
                 throw $e;
             }
         }
         $prev = new \ReflectionProperty('Exception', 'previous');
         $prev->setAccessible(true);
         $prev->setValue($wrapper, $exception);
         throw $e;
     }
     $event->setResponse($response);
 }
开发者ID:ccq18,项目名称:EduSoho,代码行数:25,代码来源:ExceptionListener.php

示例2: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($event->getException() instanceof AreasNotSupportedException) {
         $subRequest = $this->httpUtils->createRequest($event->getRequest(), 'cantiga_error_areas_not_supported');
         $event->setResponse($event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true));
     }
 }
开发者ID:zyxist,项目名称:cantiga,代码行数:7,代码来源:ErrorListener.php

示例3: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!(Ki_ENVIRONMENT == 'prod') || Ki_ENVIRONMENT == 'prod' && Ki_DEBUG === true) {
         // Si retorna muestra el error detallado.
         return;
     }
     $Exception = $event->getException();
     $status = $Exception->getStatusCode();
     $message = $Exception->getMessage();
     /**
      * @var $view ViewBuilder
      */
     $view = Service::get('view');
     /**
      * @var $request Request
      */
     $request = Service::get('new.request');
     $request->setMethod('GET');
     $request = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
     if (in_array($status, array(404))) {
         $content = $view->render('exceptions/error404', array('exception_message' => $message));
     } else {
         if (in_array($status, array(401, 403))) {
             $content = $view->render('exceptions/error403', array('exception_message' => $message));
         } else {
             if (in_array($status, array(409))) {
                 $content = $view->render('exceptions/error409', array('exception_message' => $message));
             }
         }
     }
     $request->setContent($content);
     // Envia la respuesta
     $event->setResponse($request);
 }
开发者ID:kodazzi,项目名称:framework,代码行数:34,代码来源:ExceptionListener.php

示例4: 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;
 }
开发者ID:llinder,项目名称:FrameworkBenchmarks,代码行数:25,代码来源:ExceptionListener.php

示例5: onComunidadNoSeleccionadaException

 public function onComunidadNoSeleccionadaException(GetResponseForExceptionEvent $event)
 {
     $kernel = $event->getKernel();
     $exception = $event->getException();
     if (!$exception instanceof ComunidadNoSeleccionadaException) {
         return;
     }
     $kernel->handle($event->getRequest(), HttpKernel::SUB_REQUEST);
 }
开发者ID:javiermadueno,项目名称:futbol,代码行数:9,代码来源:ComunidadNoSeleccionadaExceptionListener.php

示例6: 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,
            // keep for BC -- as $format can be an argument of the controller callable
            // see src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
            // @deprecated in 2.4, to be removed in 3.0
            '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($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), false);

            // set handling to false otherwise it wont be able to handle further more
            $handling = false;

            $wrapper = $e;

            while ($prev = $wrapper->getPrevious()) {
                if ($exception === $wrapper = $prev) {
                    throw $e;
                }
            }

            $prev = new \ReflectionProperty('Exception', 'previous');
            $prev->setAccessible(true);
            $prev->setValue($wrapper, $exception);

            throw $e;
        }

        $event->setResponse($response);

        $handling = false;
    }
开发者ID:jplagahit,项目名称:brdsdev,代码行数:55,代码来源:ExceptionListener.php

示例7: onException

 public function onException(GetResponseForExceptionEvent $event)
 {
     $request = Request::create($this->error_path);
     $request->attributes->add(array('exception' => FlattenException::create($event->getException())));
     try {
         $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
     } catch (\Exception $e) {
         return;
     }
     $event->setResponse($response);
 }
开发者ID:cmsx,项目名称:kernel,代码行数:11,代码来源:EventListener.php

示例8: onExceptionThrown

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onExceptionThrown(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $kernel = $event->getKernel();
     // Load errorCode Controller if exist else throw exception again
     if ($exception instanceof NotFoundHttpException) {
         $response = $kernel->handle(Request::create('_/Error/code404'), HttpKernelInterface::MASTER_REQUEST, false);
     } else {
         $response = $kernel->handle(Request::create('_/Error/code500'), HttpKernelInterface::MASTER_REQUEST, false);
     }
     $event->setResponse($response);
 }
开发者ID:itkg,项目名称:core,代码行数:15,代码来源:ResponseExceptionListener.php

示例9: 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

示例10: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!($exception = $event->getException()) instanceof ApiException) {
         return;
     }
     $request = $event->getRequest();
     $attributes = array('_controller' => $this->controller, 'exception' => $exception, 'format' => $request->getRequestFormat('json'));
     $request = $request->duplicate(null, null, $attributes);
     $request->setMethod('GET');
     $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
     $event->setResponse($response);
     $event->stopPropagation();
 }
开发者ID:open-orchestra,项目名称:open-orchestra-base-api-bundle,代码行数:16,代码来源:HttpExceptionSubscriber.php

示例11: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     /** @var HttpExceptionInterface $exception */
     $exception = $event->getException();
     if ($exception instanceof HttpExceptionInterface) {
         $request = clone $event->getRequest();
         $request->attributes->set('_controller', 'UCCA\\Controllers\\HttpExceptionController');
         $request->attributes->set('status_code', $exception->getStatusCode());
         $request->attributes->remove('action');
         $request->query->remove('action');
         $request->request->remove('action');
         $event->setResponse($event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false));
     }
 }
开发者ID:Asmerok,项目名称:UCCA,代码行数:14,代码来源:KernelExceptionSubscriber.php

示例12: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     static $handling;
     if (true === $handling) {
         return false;
     }
     $handling = true;
     $exception = $event->getException();
     $request = $event->getRequest();
     if (null !== $this->logger) {
         $message = sprintf('%s: %s (uncaught exception) at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine());
         if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {
             $this->logger->crit($message);
         } else {
             $this->logger->err($message);
         }
     } else {
         error_log(sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
     }
     $logger = $this->logger instanceof DebugLoggerInterface ? $this->logger : null;
     $flattenException = FlattenException::create($exception);
     if ($exception instanceof HttpExceptionInterface) {
         $flattenException->setStatusCode($exception->getStatusCode());
         $flattenException->setHeaders($exception->getHeaders());
     }
     $attributes = array('_controller' => $this->controller, 'exception' => $flattenException, 'logger' => $logger, '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) {
         $message = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage());
         if (null !== $this->logger) {
             if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {
                 $this->logger->crit($message);
             } else {
                 $this->logger->err($message);
             }
         } else {
             error_log($message);
         }
         // set handling to false otherwise it wont be able to handle further more
         $handling = false;
         // re-throw the exception as this is a catch-all
         throw $exception;
     }
     $event->setResponse($response);
     $handling = false;
 }
开发者ID:navassouza,项目名称:symfony,代码行数:49,代码来源:ExceptionListener.php

示例13: renderErrorPage

 /**
  * Render a control panel error page for the exception.
  *
  * @param GetResponseForExceptonEvent $event The event object
  */
 public function renderErrorPage(GetResponseForExceptionEvent $event)
 {
     // Skip if working locally
     if ('local' === $this->get('env')) {
         return false;
     }
     // Skip if the requested route is not in the control panel
     if (!is_array($event->getRequest()->get('_route_collections')) || !in_array('ms.cp', $event->getRequest()->get('_route_collections'))) {
         return false;
     }
     $request = $event->getRequest()->duplicate(null, null, array('_controller' => 'Message\\Mothership\\ControlPanel\\Controller\\Error::exception', '_format' => $event->getRequest()->getRequestFormat(), 'exception' => $event->getException()));
     $request->setMethod('GET');
     $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
     $event->setResponse($response);
 }
开发者ID:mothership-ec,项目名称:cog-mothership-cp,代码行数:20,代码来源:EventListener.php

示例14: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $exceptionClass = get_class($exception);
     if (isset($this->redirections[$exceptionClass]) && !empty($this->redirections[$exceptionClass])) {
         switch (true) {
             case $exception instanceof PermissionRequiredException:
                 break;
             default:
                 return;
         }
         $kernel = $event->getKernel();
         $request = $event->getRequest()->duplicate(null, null, ['_controller' => $this->redirections[$exceptionClass], 'exception' => $exception]);
         $response = $kernel->handle($request, HttpKernelInterface::SUB_REQUEST, false);
         $event->setResponse($response);
     }
 }
开发者ID:ymarillet,项目名称:sknife,代码行数:17,代码来源:ExceptionListener.php

示例15: 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


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