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


PHP GetResponseForExceptionEvent::getRequestType方法代码示例

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


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

示例1: onKernelException

 /**
  * Renders the defined {@see ExceptionListener::$errorTemplate}, which has been defined via YAML
  * settings, on exception.
  *
  * Note, that the function is only called, if the *debug value* is set or *error pages* are
  * enabled via Parameter *stvd.error_page.enabled*.
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     // don't do anything if it's not the master request
     if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
         return;
     }
     // You get the exception object from the received event
     $exception = $event->getException();
     // Customize your response object to display the exception details
     $response = new Response();
     // set response content
     $response->setContent($this->templating->render($this->errorTemplate, array('exception' => $exception)));
     // HttpExceptionInterface is a special type of exception that
     // holds status code and header details
     if ($exception instanceof HttpExceptionInterface) {
         $response->setStatusCode($exception->getStatusCode());
         $response->headers->replace($exception->getHeaders());
     } else {
         // If the exception's status code is not valid, set it to *500*. If it's valid, the
         // status code will be transferred to the response.
         if ($exception->getCode()) {
             $response->setStatusCode($exception->getCode());
         } else {
             $response->setStatusCode(500);
         }
     }
     // Send the modified response object to the event
     $event->setResponse($response);
 }
开发者ID:intermundiasolutions,项目名称:CjwPublishToolsBundle,代码行数:38,代码来源:ExceptionListener.php

示例2: onCoreException

 /**
  * Handles the onCoreException event.
  *
  * @param GetResponseForExceptionEvent $event A GetResponseForExceptionEvent instance
  */
 public function onCoreException(GetResponseForExceptionEvent $event)
 {
     if ($this->onlyMasterRequests && HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $this->exception = $event->getException();
 }
开发者ID:rfc1483,项目名称:blog,代码行数:12,代码来源:ProfilerListener.php

示例3: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $request = $event->getRequest();
     if ('' !== rtrim($request->getPathInfo(), '/')) {
         return;
     }
     $ex = $event->getException();
     if (!$ex instanceof NotFoundHttpException || !$ex->getPrevious() instanceof ResourceNotFoundException) {
         return;
     }
     $locale = $this->localeResolver->resolveLocale($request, $this->locales) ?: $this->defaultLocale;
     $request->setLocale($locale);
     $params = $request->query->all();
     unset($params['hl']);
     $response = new RedirectResponse($request->getBaseUrl() . '/' . $locale . '/' . ($params ? '?' . http_build_query($params) : ''));
     $response->setPrivate();
     $response->setMaxAge(0);
     $response->setSharedMaxAge(0);
     $response->headers->addCacheControlDirective('must-revalidate', true);
     $response->headers->addCacheControlDirective('no-store', true);
     $event->setResponse($response);
 }
开发者ID:visionappscz,项目名称:JMSI18nRoutingBundle,代码行数:25,代码来源:LocaleChoosingListener.php

示例4: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $request = $event->getRequest();
     if (!in_array($request->getRequestFormat(), array('soap', 'xml'))) {
         return;
     } elseif ('xml' === $request->getRequestFormat() && '_webservice_call' !== $request->attributes->get('_route')) {
         return;
     }
     $attributes = $request->attributes;
     if (!($webservice = $attributes->get('webservice'))) {
         return;
     }
     if (!$this->container->has(sprintf('besimple.soap.context.%s', $webservice))) {
         return;
     }
     // hack to retrieve the current WebService name in the controller
     $request->query->set('_besimple_soap_webservice', $webservice);
     $exception = $event->getException();
     if ($exception instanceof \SoapFault) {
         $request->query->set('_besimple_soap_fault', $exception);
     }
     parent::onKernelException($event);
 }
开发者ID:boskee,项目名称:BeSimpleSoapBundle,代码行数:26,代码来源:SoapExceptionListener.php

示例5: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($exception instanceof AccessDeniedException && $this->admin->inAdmin() && $event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
         $response = new RedirectResponse($this->router->generate('glory_admin_login'));
         $event->setResponse($response);
     }
 }
开发者ID:foreverglory,项目名称:admin-bundle,代码行数:8,代码来源:LoginDisplayListener.php

示例6: ensureResponse

 protected function ensureResponse($response, GetResponseForExceptionEvent $event)
 {
     if ($response instanceof Response) {
         $event->setResponse($response);
     } else {
         $viewEvent = new GetResponseForControllerResultEvent($this->app['kernel'], $event->getRequest(), $event->getRequestType(), $response);
         $this->app['dispatcher']->dispatch(KernelEvents::VIEW, $viewEvent);
         if ($viewEvent->hasResponse()) {
             $event->setResponse($viewEvent->getResponse());
         }
     }
 }
开发者ID:ahmedibr,项目名称:project,代码行数:12,代码来源:ExceptionListenerWrapper.php

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

示例8: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $request = $event->getRequest();
     if ('' !== rtrim($request->getPathInfo(), '/')) {
         return;
     }
     $ex = $event->getException();
     if (!$ex instanceof NotFoundHttpException || !$ex->getPrevious() instanceof ResourceNotFoundException) {
         return;
     }
     $event->setResponse(new RedirectResponse($request->getBaseUrl() . '/' . $request->getPreferredLanguage(array_merge(array($this->defaultLocale), $this->locales)) . $request->getPathInfo()));
 }
开发者ID:natxet,项目名称:JMSI18nRoutingBundle,代码行数:15,代码来源:LocaleChoosingListener.php

示例9: handle

 public function handle(GetResponseForExceptionEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     if (!$this->_handlingExceptions) {
         return;
     }
     $exception = $event->getException();
     if (!$this->_handlingHttp404s) {
         if ($exception instanceof HttpException && $exception->getStatusCode() === 404) {
             return;
         }
     }
     $this->mail($exception, $event->getRequest(), array(), false);
 }
开发者ID:ehough,项目名称:emailerrors-bundle,代码行数:16,代码来源:KernelExceptionHandler.php

示例10: onKernelException

 /**
  * Handle the event
  *
  * @param GetResponseForExceptionEvent $event event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $exception = $event->getException();
     if ($exception instanceof HttpException) {
         if (500 === $exception->getStatusCode() || 404 === $exception->getStatusCode() && true === $this->handle404 || in_array($exception->getStatusCode(), $this->handleHTTPcodes)) {
             $this->createMailAndSend($exception, $event->getRequest());
         }
     } else {
         $sendMail = !in_array(get_class($exception), $this->ignoredClasses);
         if ($sendMail === true) {
             $this->createMailAndSend($exception, $event->getRequest());
         }
     }
 }
开发者ID:karim-elshendy,项目名称:ErrorNotifierBundle,代码行数:22,代码来源:Notifier.php

示例11: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $request = $event->getRequest();
     if ('' !== rtrim($request->getPathInfo(), '/')) {
         return;
     }
     $ex = $event->getException();
     if (!$ex instanceof NotFoundHttpException || !$ex->getPrevious() instanceof ResourceNotFoundException) {
         return;
     }
     $locale = false;
     // if a locale has been specifically set as a query parameter, use it
     if ($request->query->has('hl')) {
         $hostLanguage = $request->query->get('hl');
         if (preg_match('#^[a-z]{2}(?:_[a-z]{2})?$#i', $hostLanguage)) {
             $locale = $hostLanguage;
         }
     }
     // check if a session exists, and if it contains a locale
     if ($locale === false && $request->hasPreviousSession()) {
         $session = $request->getSession();
         if ($session->has('_locale')) {
             $locale = $session->get('_locale');
         }
     }
     // use accept header for locale matching if sent
     if ($locale === false && ($languages = $request->getLanguages())) {
         foreach ($languages as $lang) {
             if (in_array($lang, $this->availableLocales, true)) {
                 $locale = $lang;
                 break;
             }
         }
     }
     if ($locale === false) {
         $locale = $this->defaultLocale;
     }
     $request->setLocale($locale);
     $params = $request->query->all();
     unset($params['hl']);
     $event->setResponse(new RedirectResponse($request->getBaseUrl() . '/' . $locale . '/' . ($params ? '?' . http_build_query($params) : '')));
 }
开发者ID:pitpit,项目名称:HipI18nRoutingBundle,代码行数:45,代码来源:Locale.php

示例12: onKernelException

 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $request = $event->getRequest();
     if ('' !== rtrim($request->getPathInfo(), '/')) {
         return;
     }
     $ex = $event->getException();
     if (!$ex instanceof NotFoundHttpException || !$ex->getPrevious() instanceof ResourceNotFoundException) {
         return;
     }
     $locale = $this->localeResolver->resolveLocale($request, $this->locales) ?: $this->defaultLocale;
     $request->setLocale($locale);
     $params = $request->query->all();
     unset($params['hl']);
     $event->setResponse(new RedirectResponse($request->getBaseUrl() . '/' . $locale . '/' . ($params ? '?' . http_build_query($params) : ''), 301));
 }
开发者ID:alpixel,项目名称:AlpixelCMSBundle,代码行数:22,代码来源:LocaleChoosingListener.php

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

示例14: onExceptionSendChallenge

 /**
  * Respond with a challenge on access denied exceptions if appropriate.
  *
  * On a 403 (access denied), if there are no credentials on the request, some
  * authentication methods (e.g. basic auth) require that a challenge is sent
  * to the client.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
  *   The exception event.
  */
 public function onExceptionSendChallenge(GetResponseForExceptionEvent $event)
 {
     if (isset($this->challengeProvider) && $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
         $request = $event->getRequest();
         $exception = $event->getException();
         if ($exception instanceof AccessDeniedHttpException && !$this->authenticationProvider->applies($request) && (!isset($this->filter) || $this->filter->appliesToRoutedRequest($request, FALSE))) {
             $challenge_exception = $this->challengeProvider->challengeException($request, $exception);
             if ($challenge_exception) {
                 $event->setException($challenge_exception);
             }
         }
     }
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:23,代码来源:AuthenticationSubscriber.php

示例15: onException

 /**
  * Pass exception handling to authentication manager.
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onException(GetResponseForExceptionEvent $event)
 {
     if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
         $this->authenticationProvider->handleException($event);
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:11,代码来源:AuthenticationSubscriber.php


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