Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core\update\api Class Reference

General purpose client for https://download.moodle.org/api/. More...

Public Member Functions

 find_plugin ($component, $reqversion=ANY_VERSION, $branch=null)
 Locate the given plugin in the plugin directory.
 
 get_plugin_info ($component, $version)
 Returns info about the particular plugin version in the plugins directory.
 
 validate_pluginfo_format ($data)
 Makes sure the given data format match the expected output of the pluginfo service.
 

Static Public Member Functions

static client ()
 Factory method returning an instance of the class.
 

Public Attributes

const APIROOT = 'https://download.moodle.org/api'
 The root of the standard API provider.
 
const APIVER = '1.3'
 The API version to be used by this client.
 

Protected Member Functions

 __construct ()
 Constructor is protected, use the factory method.
 
 call_pluginfo_service (array $params)
 Calls the pluginfo.php end-point with given parameters.
 
 call_service ($serviceurl, array $params=array())
 Calls the given end-point service with the given parameters.
 
 convert_branch_numbering_format ($branch)
 Converts the given branch from XY format to the X.Y format.
 
 get_serviceurl_pluginfo ()
 Returns URL of the pluginfo.php API end-point.
 

Detailed Description

General purpose client for https://download.moodle.org/api/.

The API provides proxy access to public information about plugins available in the Moodle Plugins directory. It is used when we are checking for updates, resolving missing dependecies or installing a plugin. This client can be used to:

  • obtain information about particular plugin version
  • locate the most suitable plugin version for the given Moodle branch

TODO:

  • Convert core\update\checker to use this client too, so that we have a single access point for all the API services.
  • Implement client method for pluglist.php even if it is not actually used by the Moodle core.
License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ call_pluginfo_service()

core\update\api::call_pluginfo_service ( array $params)
protected

Calls the pluginfo.php end-point with given parameters.

Parameters
array$params
Return values
core\update\remote_info|bool

◆ call_service()

core\update\api::call_service ( $serviceurl,
array $params = array() )
protected

Calls the given end-point service with the given parameters.

Returns false on cURL error and/or SSL verification failure. Otherwise an object with the response, cURL info and HTTP status message is returned.

Parameters
string$serviceurl
array$params
Return values
stdClass|bool

◆ client()

static core\update\api::client ( )
static

Factory method returning an instance of the class.

Return values
core\update\apiclient instance

◆ convert_branch_numbering_format()

core\update\api::convert_branch_numbering_format ( $branch)
protected

Converts the given branch from XY format to the X.Y format.

The syntax of $CFG->branch uses the XY format that suits the Moodle docs versioning and stable branches numbering scheme. The API at download.moodle.org uses the X.Y numbering scheme.

Parameters
int$branchmoodle branch in the XY format (e.g. 29, 30, 31 etc)
Return values
stringmoodle branch in the X.Y format (e.g. 2.9, 3.0, 3.1 etc)

◆ find_plugin()

core\update\api::find_plugin ( $component,
$reqversion = ANY_VERSION,
$branch = null )

Locate the given plugin in the plugin directory.

Uses pluginfo.php end-point to find a plugin with the given component name, that suits best for the given Moodle core branch. Minimal required plugin version can be specified. This is typically used for resolving dependencies.

False is returned on error, or if there is no plugin with such component name found in the plugins directory via the API.

If a plugin with the given component name is found, data about the plugin are returned as an object. The ->version property of the object contains the information about the particular plugin version that matches best the given critera. The ->version property is false if no suitable version of the plugin was found (yet the plugin itself is known).

Parameters
string$componentfrankenstyle name of the plugin
string | int$reqversionminimal required version of the plugin, defaults to ANY_VERSION
int$branchmoodle core branch such as 29, 30, 31 etc, defaults to $CFG->branch
Return values
core\update\remote_info|bool

◆ get_plugin_info()

core\update\api::get_plugin_info ( $component,
$version )

Returns info about the particular plugin version in the plugins directory.

Uses pluginfo.php end-point to find the given plugin version in the Moodle plugins directory. This is typically used to handle the installation request coming from the plugins directory (aka clicking the "Install" button there).

If a plugin with the given component name is found, data about the plugin are returned as an object. The ->version property of the object contains the information about the requested plugin version. The ->version property is false if the requested version of the plugin was not found (yet the plugin itself is known).

Parameters
string$componentfrankenstyle name of the plugin
int$versionplugin version as declared via $plugin->version in its version.php
Return values
core\update\remote_info|bool

◆ get_serviceurl_pluginfo()

core\update\api::get_serviceurl_pluginfo ( )
protected

Returns URL of the pluginfo.php API end-point.

Return values
string

◆ validate_pluginfo_format()

core\update\api::validate_pluginfo_format ( $data)

Makes sure the given data format match the expected output of the pluginfo service.

Object validated by this method is guaranteed to contain all the data provided by the pluginfo.php version this client works with (self\APIVER).

Parameters
stdClass$data
Return values
core\update\remote_info|boolfalse if data are not valid, original data otherwise

The documentation for this class was generated from the following file: