本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseForExceptionEvent::getRequest方法的具体用法?PHP GetResponseForExceptionEvent::getRequest怎么用?PHP GetResponseForExceptionEvent::getRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
的用法示例。
在下文中一共展示了GetResponseForExceptionEvent::getRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
$pathInfo = explode('/', $event->getRequest()->getPathInfo());
if (isset($pathInfo[1]) && in_array($pathInfo[1], $this->locales)) {
$event->getRequest()->setLocale($pathInfo[1]);
}
}
示例2: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*
* @return RedirectResponse|null
*
* @throws \LogicException If the current page is inside the page range
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if (!$exception instanceof OutOfBoundsException) {
return;
}
$pageNumber = $exception->getPageNumber();
$pageCount = $exception->getPageCount();
if ($pageCount < 1) {
return;
// No pages...so let the exception fall through.
}
$queryBag = clone $event->getRequest()->query;
if ($pageNumber > $pageCount) {
$queryBag->set($exception->getRedirectKey(), $pageCount);
} elseif ($pageNumber < 1) {
$queryBag->set($exception->getRedirectKey(), 1);
} else {
return;
// Super weird, because current page is within the bounds, fall through.
}
if (null !== ($qs = http_build_query($queryBag->all(), '', '&'))) {
$qs = '?' . $qs;
}
// Create identical uri except for the page key in the query string which
// was changed by this listener.
//
// @see Symfony\Component\HttpFoundation\Request::getUri()
$request = $event->getRequest();
$uri = $request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo() . $qs;
$event->setResponse(new RedirectResponse($uri));
}
示例3: 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($event->getRequest()->getMethod());
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;
}
示例4: onException
/**
* Catches a form AJAX exception and build a response from it.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
* The event to process.
*/
public function onException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$request = $event->getRequest();
// Render a nice error message in case we have a file upload which exceeds
// the configured upload limit.
if ($exception instanceof BrokenPostRequestException && $request->query->has(FormBuilderInterface::AJAX_FORM_REQUEST)) {
$this->drupalSetMessage($this->t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', ['@size' => $this->formatSize($exception->getSize())]), 'error');
$response = new AjaxResponse();
$status_messages = ['#type' => 'status_messages'];
$response->addCommand(new ReplaceCommand(NULL, $status_messages));
$response->headers->set('X-Status-Code', 200);
$event->setResponse($response);
return;
}
// Extract the form AJAX exception (it may have been passed to another
// exception before reaching here).
if ($exception = $this->getFormAjaxException($exception)) {
$request = $event->getRequest();
$form = $exception->getForm();
$form_state = $exception->getFormState();
// Set the build ID from the request as the old build ID on the form.
$form['#build_id_old'] = $request->get('form_build_id');
try {
$response = $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, []);
// Since this response is being set in place of an exception, explicitly
// mark this as a 200 status.
$response->headers->set('X-Status-Code', 200);
$event->setResponse($response);
} catch (\Exception $e) {
// Otherwise, replace the existing exception with the new one.
$event->setException($e);
}
}
}
示例5: onKernelExceptionView
/**
* @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
*
* @throws \Exception
*/
public function onKernelExceptionView(GetResponseForExceptionEvent $event)
{
if (!$event->getRequest()->attributes->get('is_rest_request')) {
return;
}
$event->setResponse($this->viewDispatcher->dispatch($event->getRequest(), $event->getException()));
$event->stopPropagation();
}
示例6: onKernelException
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if (!$exception instanceof StepException) {
return;
}
$reflection = new \ReflectionClass(get_class($exception));
$event->getRequest()->getSession()->getBag('flashes')->add('error', $this->translator->trans('error.recipe.' . lcfirst($reflection->getShortName())));
$targetUrl = $event->getRequest()->getSession()->get(AdminRecipeController::EXCEPTION_TARGET_URL_KEY, $event->getRequest()->getUri());
$event->setResponse(new RedirectResponse($targetUrl));
}
示例7: onKernelException
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (strpos($event->getRequest()->attributes->get('_controller'), '::')) {
$implementedInterfaces = class_implements(explode('::', $event->getRequest()->attributes->get('_controller'))[0]);
if (in_array(self::SYNC_MARKER_INTERFACE, $implementedInterfaces, TRUE)) {
$exception = $event->getException();
$message = sprintf('`%s` [uncaught exception]: throws `%s` (code `%s`) at `%s` line `%s`', get_class($exception), $exception->getMessage(), $exception->getCode(), $exception->getFile(), $exception->getLine());
$this->_logger->error($message, ['exception' => $exception]);
}
}
}
示例8: onKernelException
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$event->getRequest()->attributes->has('_api_result') && !$this->requestMatcher->matches($event->getRequest())) {
return;
}
$errorFactory = $this->errorFactory;
/** @var ErrorInterface $error */
$error = $errorFactory($event->getException());
// Tell Symfony to not use 500 as status code.
$response = new JsonResponse(array_merge(['ok' => false, 'error' => $error->getName()], $error->getData()), 200, ['x-status-code' => 200]);
$event->setResponse($response);
}
示例9: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (strpos($event->getRequest()->attributes->get('_controller'), 'Api\\Resource') !== false) {
$exception = $event->getException();
if ($exception instanceof HttpException) {
$statusCode = $exception->getStatusCode();
} else {
$statusCode = 500;
}
$event->setResponse($this->formatter->format($event->getRequest(), [], $statusCode));
}
}
示例10: onKernelException
/**
* If exception type is 404, display the Orchestra 404 node instead of Symfony exception
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ($event->getException() instanceof DisplayBlockException) {
$event->getRequest()->setRequestFormat('fragment.' . $event->getRequest()->getRequestFormat());
$event->setException($event->getException()->getPrevious());
} elseif ($event->getException() instanceof HttpExceptionInterface && '404' == $event->getException()->getStatusCode()) {
$this->setCurrentSiteInfo(trim($this->request->getHost(), '/'), trim($this->request->getPathInfo(), '/'));
if ($html = $this->getCustom404Html()) {
$event->setResponse(new Response($html, 404));
}
}
}
示例11: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if ($exception instanceof HttpException) {
return;
}
$culprit = null;
if ($event->getRequest()->attributes->has('_controller')) {
$culprit = $event->getRequest()->attributes->get('_controller');
}
$metadata = new Metadata();
$metadata->addMetadatum('culprit', $culprit);
$this->errorHandler->handleException($exception, $metadata);
}
示例12: 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);
}
示例13: onKernelException
public function onKernelException(GetResponseForExceptionEvent $event)
{
$ex = $event->getException();
if ($ex instanceof BadRequestException) {
$event->setResponse($this->renderer->render($event->getRequest(), $ex));
}
}
示例14: 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);
}
示例15: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*
* @return string
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$event->getRequest()->isXmlHttpRequest()) {
return self::RESULT_NOT_AJAX;
}
if (substr($event->getRequest()->getPathInfo(), 0, strlen($this->backendRoutesPrefix)) != $this->backendRoutesPrefix) {
return self::RESULT_NOT_BACKEND_REQUEST;
}
$e = $event->getException();
$response = null;
if ($e instanceof AccessDeniedException) {
$msg = "Your session has expired and you need to re-login or you don't have privileges to perform given action.";
$response = new JsonResponse(array('success' => false, 'message' => T::trans($msg)), 403);
$event->setResponse($response);
}
}