add helper checkXmlHttpRequest

This commit is contained in:
Manuel Raynaud
2013-09-12 16:45:32 +02:00
parent 22f42c8d9c
commit 2bf6ee51e1
6 changed files with 57 additions and 17 deletions

View File

@@ -25,6 +25,7 @@ namespace Thelia\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Exception\InvalidParameterException;
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
@@ -263,4 +264,16 @@ class BaseController extends ContainerAware
{
return $this->container->getParameter('kernel.debug');
}
/**
* check if the current http request is a XmlHttpRequest.
*
* If not, send a
*/
protected function checkXmlHttpRequest()
{
if(false === $this->getRequest()->isXmlHttpRequest() && false === $this->isDebug()) {
throw new AccessDeniedHttpException();
}
}
}