/** * Check the request against $action_checks defined for * the controller action * * @param Symfony\Component\HttpFoundation\Request $request * @param string $action * Controller action name */ public function checkRequest($request, $action) { $request_method = strtolower($request->getMethod()); if (!empty($this->action_checks) && isset($this->action_checks[$action])) { $allowed_methods = $this->action_checks[$action]['methods']; $xhr_required = $this->action_checks[$action]['xhr']; // test http method if (isset($allowed_methods) && !in_array($request_method, $allowed_methods)) { header('HTTP/1.0 400 Bad Request'); exit('Wrong HTTP request method'); } // test for XHR header if (isset($xhr_required) && $xhr_required === TRUE && $request->headers->get('x-requested-with') != 'XMLHttpRequest') { header('HTTP/1.0 400 Bad Request'); exit('Required HTTP request header missing'); } } return $this; }