Moodle's API is a mix of library functions and classes. Moodle was originally based on the version 4 series of PHP, and as such, most of its API is built around functions defined in PHP library files. However, some of the newer constructs of Moodle use object-oriented structures and as such provide extensible classes.
Most of Moodle's main libraries are kept in the /lib/
directory. All of these files generally adhere to the naming convention [function]lib.php
. Some of the examples are textlib.php
and weblib.php
. These library files contain Moodle's API.
Almost all of the core libraries are included in the execution stream when you load config.php
via its inclusion of /lib/setup.php
. The setup.php
file includes these via the following lines:
require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings require_once($CFG->libdir .'/weblib.php'); // Functions for producing HTML require_once($CFG->libdir .'/dmllib.php'); // Functions to handle DB data (DML) require_once($CFG->libdir .'/datalib.php'); // Legacy lib with a big-mix of functions. require_once($CFG->libdir .'/accesslib.php'); // Access control functions require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions require_once($CFG->libdir .'/eventslib.php'); // Events functions require_once($CFG->libdir .'/grouplib.php'); // Groups functions
These by no means define all of the functions available in Moodle, and in fact each of these libraries may include other libraries. However, the core of the functions that you will need are contained within these libraries. In fact, the ones that you will need to look at the most are:
moodlelib.php
weblib.php
dmllib.php
accesslib.php
grouplib.php
There are many other libraries that you will use, as you start to carry out specific functions. Most of these are stored in the /lib/
directory. However, others may be in specific functional areas such as /course/
and /blocks/
.
Many of the specific libraries define classes that you can use. Libraries such as /lib/pagelib.php
and /lib/formslib.php
define classes that are designed to be extended in order to handle output to screen. pagelib.php
defines specific page types, with all of the functions necessary to manage page output and create your own page types. Likewise, formslib.php
defines Moodle's implementation of the PEAR QuickForm classes in order to handle web-based forms.
There is no single, all-encompassing document for all of Moodle's API. However, you can find out more about each specific area in the developer documentation at Moodle Docs. A good place to start is http://docs.moodle.org/en/Development:Developer_documentation#Core_components_that_affect_everything.
Another resource that can help is the Moodle code cross reference. This is an online resource that is generated from the code and inline comments in order to produce documentation. It is generated automatically by using PHPXref. The reference can be found at http://docs.moodle.org/en/Development:Code_Cross-Reference. Note that it may not be up-to-date and maintained. Still, it does provide an easy overview.