interface authorizer_interface

Authorizer Interface.

Defines the contract for validating user permissions and login requirements, isolating Moodle's capability system from the business logic.

Constants

CONTEXT_SYSTEM

Context level constant for SYSTEM.

CONTEXT_COURSECAT

Context level constant for COURSE CATEGORY.

CONTEXT_COURSE

Context level constant for COURSE.

CONTEXT_MODULE

Context level constant for MODULE.

CONTEXT_BLOCK

Context level constant for BLOCK.

CONTEXT_USER

Context level constant for USER.

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 to the system or a specific course.

Details

at line 72
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 84
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 94
void require_login(int|null $courseid = null, bool $autologinguest = true)

Requires the user to be logged in to the system or a specific course.

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