本文整理汇总了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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
}
示例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());
}
}
}
示例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);
}
示例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()));
}
示例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);
}
示例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());
}
}
}
示例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) : '')));
}
示例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));
}
示例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);
}
示例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);
}
}
}
}
示例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);
}
}