[ticket/13361] Support ajax request (send a json response)

PHPBB3-13361
This commit is contained in:
Tristan Darricau 2015-01-10 17:14:14 +01:00
parent b00d02496e
commit 74e8f9bd4e

View file

@ -14,6 +14,7 @@
namespace phpbb\event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
@ -64,6 +65,8 @@ class kernel_exception_subscriber implements EventSubscriberInterface
$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($message), $exception->get_parameters()));
}
if (!$event->getRequest()->isXmlHttpRequest())
{
$this->template->assign_vars(array(
'MESSAGE_TITLE' => $this->user->lang('INFORMATION'),
'MESSAGE_TEXT' => $message,
@ -76,6 +79,19 @@ class kernel_exception_subscriber implements EventSubscriberInterface
page_footer(true, false, false);
$response = new Response($this->template->assign_display('body'), 500);
}
else
{
$data = array();
$data['message'] = $message;
if (defined('DEBUG'))
{
$data['trace'] = $exception->getTrace();
}
$response = new JsonResponse($message, 500);
}
if ($exception instanceof HttpExceptionInterface)
{