Composer/autoloading
MediaWiki has a full autoloading regimen that follows PSR standards[1][2][3][4][5]. Jeroen DeDauw wrote a blog post in 2013 entitled "Introduction to Composer for MediaWiki developers"
As a PHP Dependency manager, of course Composer follows these same standards and integrates with the MediaWiki software. MediaWiki delegates some authority to composer for 3rd-party dependency resolution.
In brief:
MediaWiki 1.25+ depends on some external libraries which are managed with Composer. Composer creates an autoloader at
vendor/autoload.php
, which is included byWebStart.php
.[6]
Composer.json best practices for MediaWiki developers
Configuration
- prepend-autoloader:
false
. Composer's autoloader is slower than MediaWiki's, and most of the classes being loaded are likely to be found inside MediaWiki, so append the Composer autoloader instead of prepending it. See this ancient 2014 thread for some more details. - optimize-autoloader:
true
. No reason not to optimize.
Dependencies
Use a tag.
If none is available, then use a specific (SemVer) version.
Last resort: use a specific SHA1 commit id.[7]
Optimize
"Composer optimize autoloader" refers to a feature within the Composer dependency manager for PHP that allows you to improve the performance of your application by optimizing how classes are loaded at runtime, essentially speeding up the process of finding and including necessary PHP files when a class is called, by generating a classmap that directly maps class names to file locations, resulting in faster autoloading times, especially in production environments.
Due to the way PSR-0/4 autoloading rules are defined, the Composer autoloader checks the filesystem before resolving a classname conclusively. In production, Composer allows for optimization to convert the PSR-0 and PSR-4 autoloading rules into classmap rules, making autoloading quite a bit faster.[8]
References
- ↑ https://www.mediawiki.org/wiki/Manual:$wgAutoloadClasses
- ↑ https://www.mediawiki.org/wiki/Manual:$wgAutoloadLocalClasses
- ↑ https://www.mediawiki.org/wiki/Manual:GenerateLocalAutoload.php
- ↑ https://phabricator.wikimedia.org/source/mediawiki/browse/master/maintenance/generateLocalAutoload.php
- ↑ https://www.mediawiki.org/wiki/Manual:AutoLoader.php
- ↑ https://www.mediawiki.org/wiki/Composer#Usage_in_MediaWiki_core
- ↑ https://www.mediawiki.org/wiki/Manual:Composer.json_best_practices
- ↑ https://getcomposer.org/doc/articles/autoloader-optimization.md