moodle_authorizer implements authorizer_interface
Concrete Moodle Authorizer Adapter.
Implements capability checks by orchestrating Moodle context retrieval and capability checking.
Table of Contents
Interfaces
- authorizer_interface
- Authorizer Interface.
Methods
- authorize() : void
- Requires a specific capability, throwing an exception if not met.
- can() : bool
- Checks if a user has a specific capability.
- require_login() : void
- Requires the user to be logged in.
- resolve_context() : context
- Resolves Moodle's \context object based on the level and instance ID.
Methods
authorize()
Requires a specific capability, throwing an exception if not met.
public
authorize(string $capability[, int $contextlevel = self::CONTEXT_SYSTEM ][, int $instanceid = 0 ][, null|int $userid = null ]) : void
Parameters
- $capability : string
-
The capability name
- $contextlevel : int = self::CONTEXT_SYSTEM
-
The context level
- $instanceid : int = 0
-
The instance ID
- $userid : null|int = null
-
The user ID. Null for the current user.
Tags
can()
Checks if a user has a specific capability.
public
can(string $capability[, int $contextlevel = self::CONTEXT_SYSTEM ][, int $instanceid = 0 ][, null|int $userid = null ]) : bool
Parameters
- $capability : string
-
The capability name
- $contextlevel : int = self::CONTEXT_SYSTEM
-
The context level
- $instanceid : int = 0
-
The instance ID corresponding to the context level
- $userid : null|int = null
-
The user ID. Null for the current user.
Return values
bool —True if the user has the capability, false otherwise
require_login()
Requires the user to be logged in.
public
require_login([null|int $courseid = null ][, bool $autologinguest = true ]) : void
Parameters
- $courseid : null|int = null
-
The course ID, or null for system login
- $autologinguest : bool = true
-
Whether guest auto-login is allowed
Tags
resolve_context()
Resolves Moodle's \context object based on the level and instance ID.
private
resolve_context(int $contextlevel, int $instanceid) : context
Parameters
- $contextlevel : int
-
The mapping constant defined in authorizer_interface
- $instanceid : int
-
The corresponding instance ID