當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。