Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

(no description)

File Size: 340 lines (11 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: matrix_client  - X-Ref

The abstract class for a versioned API client for Matrix.

Matrix uses a versioned API, and a handshake occurs between the Client (Moodle) and server, to determine the APIs available.

This client represents a version-less API client.
Versions are implemented by combining the various features into a versionedclass.
See v1p1 for example.

__construct(protected string $serverurl,protected string $accesstoken,)   X-Ref
Matrix events constructor to get the room id and refresh token usage if required.

param: string $serverurl The URL of the API server
param: string $accesstoken The admin access token

instance(string $serverurl,string $accesstoken,)   X-Ref
Return the versioned instance of the API.

param: string $serverurl The URL of the API server
param: string $accesstoken The admin access token to use
return: matrix_client

implements_feature(array|string $feature)   X-Ref
Determine if the API supports a feature.

If an Array is provided, this will return true if any of the specified features is implemented.

param: string[]|string $feature The feature to check. This is in the form of a namespaced class.
return: bool

get_supported_features()   X-Ref
Get a list of the features supported by this client.

return: string[]

require_feature(array|string $feature)   X-Ref
Require that the API supports a feature.

If an Array is provided, this is treated as a require any of the features.

param: string[]|string $feature The feature to test

require_features(array $features)   X-Ref
Require that the API supports a list of features.

All features specified will be required.

If an array is provided as one of the features, any of the items in the nested array will be required.

param: string[]|array[] $features The list of features required

get_server_url()   X-Ref
Get the URL of the server.

return: string

query_server_supports(string $serverurl)   X-Ref
Query the supported versions, and any unstable features, from the server.

Servers must implement the client versions API described here:
- https://spec.matrix.org/latest/client-server-api/#get_matrixclientversions

param: string $serverurl The server base
return: \stdClass The list of supported versions and a list of enabled unstable features

get_supported_versions()   X-Ref
Get the list of supported versions based on the available classes.

return: array

get_token()   X-Ref
Get the current token in use.

return: string

get_client()   X-Ref
Helper to fetch the HTTP Client for the instance.

return: \core\http_client

get_http_client()   X-Ref
Helper to fetch the HTTP Client.

return: \core\http_client

execute(command $command,)   X-Ref
Execute the specified command.

param: command $command
return: Response

get_version()   X-Ref
Get the API version of the current instance.

return: string

get_version_from_classname(string $classname)   X-Ref
Normalise an API version from a classname.

param: string $classname The short classname, omitting any namespace or file extension
return: string The normalised version

meets_version(string $minversion)   X-Ref
Check if the API version is at least the specified version.

param: string $minversion The minimum API version required
return: bool

requires_version(string $minversion)   X-Ref
Assert that the API version is at least the specified version.

param: string $minversion The minimum API version required