This adds support for a PSR-4 (<http://www.php-fig.org/psr/psr-4/>) autoloader, so instead of needing to manually list each class, just the namespace prefix is needed. Extensions can set a "AutoloadNamespaces" property in extension.json to register PSR-4 compatible namespaces to be autoloaded. The implementation is based off of the example implementation (<http://www.php-fig.org/psr/psr-4/examples/>) with some modifications for performance, notably cutting down on function calls, and only trying to look up classes that are namespaced. The generateLocalAutoload.php script will ignore any directory that is registered as a PSR-4 namespace. Bug: T99865 Bug: T173799 Change-Id: Id095dde37cbb40aa424fb628bd3c94e684ca2f65
22 lines
648 B
PHP
22 lines
648 B
PHP
<?php
|
|
|
|
if ( PHP_SAPI != 'cli' ) {
|
|
die( "This script can only be run from the command line.\n" );
|
|
}
|
|
|
|
require_once __DIR__ . '/../includes/AutoLoader.php';
|
|
require_once __DIR__ . '/../includes/utils/AutoloadGenerator.php';
|
|
|
|
// Mediawiki installation directory
|
|
$base = dirname( __DIR__ );
|
|
|
|
$generator = new AutoloadGenerator( $base, 'local' );
|
|
$generator->setExcludePaths( array_values( AutoLoader::getAutoloadNamespaces() ) );
|
|
$generator->initMediaWikiDefault();
|
|
|
|
// Write out the autoload
|
|
$fileinfo = $generator->getTargetFileinfo();
|
|
file_put_contents(
|
|
$fileinfo['filename'],
|
|
$generator->getAutoload( 'maintenance/generateLocalAutoload.php' )
|
|
);
|