示例#1
0
/** Called from within an action function, checks permissions for that action with the specified arguments */
function checkActionPermissionSelf($action_function, $function_args)
{
    // Error if the specified function does not exist.
    if (!function_exists($action_function)) {
        if (LOG_AUTH_FAILURES) {
            error_log("Authorization failed: action '{$action_function}' does not exist.");
        }
        return false;
    }
    // Map the function argument names to their values.  We end up with a dictionary of argument_name => argument_value
    $method = new ReflectionFunction($action_function);
    $mapped_args = array();
    $i = 0;
    foreach ($method->getParameters() as $param) {
        $param_name = $param->getName();
        if (isset($function_args[$i])) {
            $mapped_args[$param_name] = $function_args[$i];
        } else {
            if ($param->isOptional()) {
                $mapped_args[$param_name] = $param->getDefaultValue();
            } else {
                if (LOG_AUTH_FAILURES) {
                    error_log("Authorization failed: Missing one or more parameters required by {$action_function}.");
                }
                return false;
            }
        }
        $i++;
    }
    return checkActionPermission($action_function, $mapped_args);
}
示例#2
0
/** Called from within an action function, checks permissions for that action with the specified arguments */
function checkActionPermissionSelf($action_function, $function_args)
{
    // Error if the specified function does not exist.
    if (!function_exists($action_function)) {
        //echo "FAILED: action '$action_function' does not exist.<br><br>";
        return false;
    }
    // Map the function argument names to their values.  We end up with a dictionary of argument_name => argument_value
    $method = new ReflectionFunction($action_function);
    $mapped_args = array();
    $i = 0;
    foreach ($method->getParameters() as $param) {
        $param_name = $param->getName();
        $mapped_args[$param_name] = $function_args[$i];
        $i++;
    }
    return checkActionPermission($action_function, $mapped_args);
}