29require_once __DIR__ .
'/../autoload.php';
42 'MediaWiki\\' => __DIR__ .
'/',
43 'MediaWiki\\Actions\\' => __DIR__ .
'/actions/',
44 'MediaWiki\\Api\\' => __DIR__ .
'/api/',
45 'MediaWiki\\Auth\\' => __DIR__ .
'/auth/',
46 'MediaWiki\\Block\\' => __DIR__ .
'/block/',
47 'MediaWiki\\Cache\\' => __DIR__ .
'/cache/',
48 'MediaWiki\\ChangeTags\\' => __DIR__ .
'/changetags/',
49 'MediaWiki\\Composer\\' => __DIR__ .
'/composer/',
50 'MediaWiki\\Config\\' => __DIR__ .
'/config/',
51 'MediaWiki\\Content\\' => __DIR__ .
'/content/',
52 'MediaWiki\\DB\\' => __DIR__ .
'/db/',
53 'MediaWiki\\Deferred\\' => __DIR__ .
'/deferred/',
54 'MediaWiki\\Deferred\\LinksUpdate\\' => __DIR__ .
'/deferred/LinksUpdate/',
55 'MediaWiki\\Diff\\' => __DIR__ .
'/diff/',
56 'MediaWiki\\EditPage\\' => __DIR__ .
'/editpage/',
57 'MediaWiki\\Edit\\' => __DIR__ .
'/edit/',
58 'MediaWiki\\FileBackend\\LockManager\\' => __DIR__ .
'/filebackend/lockmanager/',
59 'MediaWiki\\Http\\' => __DIR__ .
'/http/',
60 'MediaWiki\\Installer\\' => __DIR__ .
'/installer/',
61 'MediaWiki\\Interwiki\\' => __DIR__ .
'/interwiki/',
62 'MediaWiki\\JobQueue\\' => __DIR__ .
'/jobqueue/',
63 'MediaWiki\\Json\\' => __DIR__ .
'/json/',
64 'MediaWiki\\Languages\\Data\\' => __DIR__ .
'/languages/data/',
65 'MediaWiki\\Linker\\' => __DIR__ .
'/linker/',
66 'MediaWiki\\Logger\\' => __DIR__ .
'/debug/logger/',
67 'MediaWiki\\Logger\\Monolog\\' => __DIR__ .
'/debug/logger/monolog/',
68 'MediaWiki\\Mail\\' => __DIR__ .
'/mail/',
69 'MediaWiki\\Page\\' => __DIR__ .
'/page/',
70 'MediaWiki\\Parser\\' => __DIR__ .
'/parser/',
71 'MediaWiki\\Password\\' => __DIR__ .
'/password/',
72 'MediaWiki\\PoolCounter\\' => __DIR__ .
'/poolcounter/',
73 'MediaWiki\\Preferences\\' => __DIR__ .
'/preferences/',
74 'MediaWiki\\RCFeed\\' => __DIR__ .
'/recentchanges/RCFeed/',
75 'MediaWiki\\Search\\' => __DIR__ .
'/search/',
76 'MediaWiki\\Search\\SearchWidgets\\' => __DIR__ .
'/search/searchwidgets/',
77 'MediaWiki\\Session\\' => __DIR__ .
'/session/',
78 'MediaWiki\\Shell\\' => __DIR__ .
'/shell/',
79 'MediaWiki\\Site\\' => __DIR__ .
'/site/',
80 'MediaWiki\\Sparql\\' => __DIR__ .
'/sparql/',
81 'MediaWiki\\SpecialPage\\' => __DIR__ .
'/specialpage/',
82 'MediaWiki\\Specials\\Contribute\\' => __DIR__ .
'/specials/Contribute',
83 'MediaWiki\\Tidy\\' => __DIR__ .
'/tidy/',
84 'MediaWiki\\User\\' => __DIR__ .
'/user/',
85 'MediaWiki\\Utils\\' => __DIR__ .
'/utils/',
86 'MediaWiki\\Widget\\' => __DIR__ .
'/widget/',
87 'Wikimedia\\' => __DIR__ .
'/libs/',
88 'Wikimedia\\Composer\\' => __DIR__ .
'/libs/composer/',
89 'Wikimedia\\Http\\' => __DIR__ .
'/libs/http/',
90 'Wikimedia\\Rdbms\\Platform\\' => __DIR__ .
'/libs/rdbms/platform/',
91 'Wikimedia\\UUID\\' => __DIR__ .
'/libs/uuid/',
97 private static $psr4Namespaces = self::CORE_NAMESPACES;
102 private static $classFiles = [];
113 self::$psr4Namespaces += $dirs;
123 self::$classFiles += $files;
142 public static function loadFile(
string $file ): void {
155 public static function loadFiles( array $files ): void {
156 foreach ( $files as $f ) {
157 self::loadFile( $f );
167 public static function find( $className ): ?string {
174 self::$classFiles[$className] ??
178 if ( !$filename && strpos( $className,
'\\' ) !==
false ) {
180 $prefix = $className;
182 while ( ( $pos = strrpos( $prefix,
'\\' ) ) !==
false ) {
184 $prefix = substr( $className, 0, $pos + 1 );
185 if ( isset( self::$psr4Namespaces[$prefix] ) ) {
186 $relativeClass = substr( $className, $pos + 1 );
188 $file = self::$psr4Namespaces[$prefix] .
190 strtr( $relativeClass,
'\\',
'/' ) .
192 if ( is_file( $file ) ) {
199 $prefix = rtrim( $prefix,
'\\' );
210 if ( $filename[0] !==
'/' && $filename[1] !==
':' ) {
211 $filename = __DIR__ .
'/../' . $filename;
223 $filename = self::find( $className );
225 if ( $filename !==
null ) {
226 require_once $filename;
231 private static function assertTesting( $method ) {
232 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
233 throw new LogicException(
"$method is not supported outside phpunit tests!" );
245 self::assertTesting( __METHOD__ );
261 self::assertTesting( __METHOD__ );
262 return self::$psr4Namespaces;
273 self::assertTesting( __METHOD__ );
275 'classFiles' => self::$classFiles,
276 'psr4Namespaces' => self::$psr4Namespaces,
289 self::assertTesting( __METHOD__ );
291 self::$classFiles = $state[
'classFiles'];
292 self::$psr4Namespaces = $state[
'psr4Namespaces'];
297spl_autoload_register( [
'AutoLoader',
'autoload' ] );
300if ( is_readable( __DIR__ .
'/../vendor/autoload.php' ) ) {
301 require_once __DIR__ .
'/../vendor/autoload.php';
302} elseif ( file_exists( __DIR__ .
'/../vendor/autoload.php' ) ) {
303 die( __DIR__ .
'/../vendor/autoload.php exists but is not readable' );
global $wgAutoloadLocalClasses
Locations of core classes Extension classes are specified with $wgAutoloadClasses.
static registerClasses(array $files)
Register a file to load the given class from.
static loadFiles(array $files)
Batch version of loadFile()
static restoreState( $state)
Returns an array representing the internal state of Autoloader, so it can be remembered and later res...
static getNamespaceDirectories()
Returns a map of namespace names to directories, per PSR4.
static registerNamespaces(array $dirs)
Register a directory to load the classes of a given namespace from, per PSR4.
static find( $className)
Find the file containing the given class.
static getState()
Returns an array representing the internal state of Autoloader, so it can be remembered and later res...
static getClassFiles()
Returns a map of class names to file paths for testing.
const CORE_NAMESPACES
A mapping of namespace => file path for MediaWiki core.
static loadFile(string $file)
Load a file that declares classes, functions, or constants.
static autoload( $className)
autoload - take a class name and attempt to load it