Search moodle.org's
Developer Documentation

See Release Notes

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

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

The class \core\update\api is defined here.

Copyright: 2015 David Mudrak <david@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 328 lines (12 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: api  - X-Ref

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.

client()   X-Ref
Factory method returning an instance of the class.

return: \core\update\api client instance

__construct()   X-Ref
Constructor is protected, use the factory method.


get_plugin_info($component, $version)   X-Ref
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).

param: string $component frankenstyle name of the plugin
param: int $version plugin version as declared via $plugin->version in its version.php
return: \core\update\remote_info|bool

find_plugin($component, $reqversion=ANY_VERSION, $branch=null)   X-Ref
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).

param: string $component frankenstyle name of the plugin
param: string|int $reqversion minimal required version of the plugin, defaults to ANY_VERSION
param: int $branch moodle core branch such as 29, 30, 31 etc, defaults to $CFG->branch
return: \core\update\remote_info|bool

validate_pluginfo_format($data)   X-Ref
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).

param: \stdClass $data
return: \core\update\remote_info|bool false if data are not valid, original data otherwise

call_pluginfo_service(array $params)   X-Ref
Calls the pluginfo.php end-point with given parameters.

param: array $params
return: \core\update\remote_info|bool

call_service($serviceurl, array $params=array()   X-Ref
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.

param: string $serviceurl
param: array $params
return: \stdClass|bool

convert_branch_numbering_format($branch)   X-Ref
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.

param: int $branch moodle branch in the XY format (e.g. 29, 30, 31 etc)
return: string moodle branch in the X.Y format (e.g. 2.9, 3.0, 3.1 etc)

get_serviceurl_pluginfo()   X-Ref
Returns URL of the pluginfo.php API end-point.

return: string