class capability_support

internal  
 

Utility functions for Moodle capabilities and permissions.

Methods

static bool|null
has(string $capability, context $context, null|int|stdClass $user = null, bool $doanything = true)

Checks if a user has a specific capability in a given context.

static string
get_string(string $capability)

Retrieves the human-readable name of a capability.

static void
require(string $capability, context $context, null|int|stdClass $user = null, bool $doanything = true, string $errormessage = 'nopermissions', string $stringfile = '')

Requires the user to have a specific capability, throwing an exception if they don't.

Details

at line 42
static bool|null has(string $capability, context $context, null|int|stdClass $user = null, bool $doanything = true)

Checks if a user has a specific capability in a given context.

Parameters

string $capability

Capability name

context $context

Context object

null|int|stdClass $user

User object or ID (null for current user)

bool $doanything

Whether to check for the 'doanything' capability

Return Value

bool|null

True if user has capability, false if not, or null on error

at line 60
static string get_string(string $capability)

Retrieves the human-readable name of a capability.

Parameters

string $capability

Capability name

Return Value

string

the localized capability name

at line 77
static void require(string $capability, context $context, null|int|stdClass $user = null, bool $doanything = true, string $errormessage = 'nopermissions', string $stringfile = '')

Requires the user to have a specific capability, throwing an exception if they don't.

Parameters

string $capability

Capability name

context $context

Context object

null|int|stdClass $user

User object or ID (null for current user)

bool $doanything

Whether to check for the 'doanything' capability

string $errormessage

Error message

string $stringfile

String file

Return Value

void

Exceptions

moodle_exception