function restful_menu_access_callback in RESTful 7
Same name and namespace in other branches
- 7.2 restful.module \restful_menu_access_callback()
Access callback; Determine access for an API call.
Parameters
$version: The version, prefixed with v (e.g. v1, v2.2).
$resource_name: The name of the resource (e.g. "articles").
Return value
bool TRUE if user is allowed to access resource.
1 string reference to 'restful_menu_access_callback'
- restful_menu in ./
restful.module - Implements hook_menu().
File
- ./
restful.module, line 405
Code
function restful_menu_access_callback($resource_name, $version = NULL) {
if (!($versions = \RestfulBase::getVersionFromRequest())) {
// No version could be found.
return;
}
if (!($handler = restful_get_restful_handler($resource_name, $versions[0], $versions[1]))) {
return;
}
if (!\RestfulBase::isValidMethod($_SERVER['REQUEST_METHOD'], FALSE)) {
return;
}
$method = strtoupper($_SERVER['REQUEST_METHOD']);
if ($method == \RestfulInterface::POST && \RestfulManager::getRequestHttpHeader('X-HTTP-Method-Override')) {
$method = strtoupper(\RestfulManager::getRequestHttpHeader('X-HTTP-Method-Override'));
}
if (!\RestfulBase::isValidMethod($method, FALSE)) {
// HTTP method is invalid.
return;
}
// Set the request and method on the handler, so access callbacks have full
// access to the request and account.
$path = func_get_args();
array_shift($path);
if (preg_match('/^v\\d+(\\.\\d+)?$/', $version)) {
array_shift($path);
}
$path = implode('/', $path);
$request = restful_parse_request();
$handler
->setPath($path);
$handler
->setMethod($method);
$handler
->setRequest($request);
try {
$access = $handler
->access();
return $access;
} catch (Exception $e) {
return FALSE;
}
}