Think about an extension, that requires a library which can be installed using composer (the library is in the require section of composer). Even with extension registration (and the old "php file" based installation method), the extension has to manually make sure, that the composer autoloader (in ./vendor/autoload.php) has been loaded as early as possible (at least earlier as the first usage of one of the required libraries). Usually this is done by one of these ways:
- load the autoloader in the main php file or a registered extension function (wgExtensionFunction)
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) { require_once __DIR__ . '/vendor/autoload.php'; }
- the above code in a callback registered in extension.json
(Example from Elastica)
This is mostly a standard way, maybe copy-paste, thing, which should be easier.
Instead of letting the extension developer handle the inclusion of the composer autoloader, there shoud be a standardised, and very simple way of loading it, e.g. thorugh extension registration. The proposed way would add a new option to the extension.json schema, which, if set, triggers extension registration to check, if an autoloader is present in the extension's vendor file and loads it right after the processing of the extension JSON-data, but before the callback (to allow an extension to use composer libraries in the callback function):
The proposed property of the extension.json schema would be:
"load_composer_autoloader": { "type": "boolean", "description": "If set to true, extension registration will try to load composer's autoloader of this extension, if present." }