class moodle_authorizer implements authorizer_interface

Concrete Moodle Authorizer Adapter.

Implements capability checks by orchestrating Moodle context retrieval and capability checking.

Methods

bool
can(string $capability, int $contextlevel = self::CONTEXT_SYSTEM, int $instanceid = 0, int|null $userid = null)

Checks if a user has a specific capability.

void
authorize(string $capability, int $contextlevel = self::CONTEXT_SYSTEM, int $instanceid = 0, int|null $userid = null)

Requires a specific capability, throwing an exception if not met.

void
require_login(int|null $courseid = null, bool $autologinguest = true)

Requires the user to be logged in.

Details

at line 45
bool can(string $capability, int $contextlevel = self::CONTEXT_SYSTEM, int $instanceid = 0, int|null $userid = null)

Checks if a user has a specific capability.

Parameters

string $capability

The capability name (e.g., 'moodle/course:view')

int $contextlevel

The context level (e.g., self::CONTEXT_COURSE)

int $instanceid

The instance ID corresponding to the context level (e.g., course ID). Default: 0

int|null $userid

The user ID. Null for the current user.

Return Value

bool

true if the user has the capability, false otherwise

at line 63
void authorize(string $capability, int $contextlevel = self::CONTEXT_SYSTEM, int $instanceid = 0, int|null $userid = null)

Requires a specific capability, throwing an exception if not met.

Parameters

string $capability

The capability name

int $contextlevel

The context level

int $instanceid

The instance ID

int|null $userid

The user ID. Null for the current user.

Return Value

void

Exceptions

moodle_exception

at line 78
void require_login(int|null $courseid = null, bool $autologinguest = true)

Requires the user to be logged in.

Parameters

int|null $courseid

The course ID, or null for system login

bool $autologinguest

Whether guest auto-login is allowed

Return Value

void

Exceptions

moodle_exception