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\\Config\\' => __DIR__ .
'/config/',
50 'MediaWiki\\Content\\' => __DIR__ .
'/content/',
51 'MediaWiki\\DB\\' => __DIR__ .
'/db/',
52 'MediaWiki\\Deferred\\' => __DIR__ .
'/deferred/',
53 'MediaWiki\\Deferred\\LinksUpdate\\' => __DIR__ .
'/deferred/LinksUpdate/',
54 'MediaWiki\\Diff\\' => __DIR__ .
'/diff/',
55 'MediaWiki\\EditPage\\' => __DIR__ .
'/editpage/',
56 'MediaWiki\\Edit\\' => __DIR__ .
'/edit/',
57 'MediaWiki\\FileBackend\\LockManager\\' => __DIR__ .
'/filebackend/lockmanager/',
58 'MediaWiki\\Http\\' => __DIR__ .
'/http/',
59 'MediaWiki\\Installer\\' => __DIR__ .
'/installer/',
60 'MediaWiki\\Interwiki\\' => __DIR__ .
'/interwiki/',
61 'MediaWiki\\JobQueue\\' => __DIR__ .
'/jobqueue/',
62 'MediaWiki\\Json\\' => __DIR__ .
'/json/',
63 'MediaWiki\\Languages\\Data\\' => __DIR__ .
'/languages/data/',
64 'MediaWiki\\Linker\\' => __DIR__ .
'/linker/',
65 'MediaWiki\\Logger\\' => __DIR__ .
'/debug/logger/',
66 'MediaWiki\\Logger\\Monolog\\' => __DIR__ .
'/debug/logger/monolog/',
67 'MediaWiki\\Mail\\' => __DIR__ .
'/mail/',
68 'MediaWiki\\Page\\' => __DIR__ .
'/page/',
69 'MediaWiki\\Parser\\' => __DIR__ .
'/parser/',
70 'MediaWiki\\PoolCounter\\' => __DIR__ .
'/poolcounter/',
71 'MediaWiki\\Preferences\\' => __DIR__ .
'/preferences/',
72 'MediaWiki\\Search\\' => __DIR__ .
'/search/',
73 'MediaWiki\\Search\\SearchWidgets\\' => __DIR__ .
'/search/searchwidgets/',
74 'MediaWiki\\Session\\' => __DIR__ .
'/session/',
75 'MediaWiki\\Shell\\' => __DIR__ .
'/shell/',
76 'MediaWiki\\Site\\' => __DIR__ .
'/site/',
77 'MediaWiki\\Sparql\\' => __DIR__ .
'/sparql/',
78 'MediaWiki\\SpecialPage\\' => __DIR__ .
'/specialpage/',
79 'MediaWiki\\Specials\\Contribute\\' => __DIR__ .
'/specials/Contribute',
80 'MediaWiki\\Tidy\\' => __DIR__ .
'/tidy/',
81 'MediaWiki\\User\\' => __DIR__ .
'/user/',
82 'MediaWiki\\Utils\\' => __DIR__ .
'/utils/',
83 'MediaWiki\\Widget\\' => __DIR__ .
'/widget/',
84 'Wikimedia\\' => __DIR__ .
'/libs/',
85 'Wikimedia\\Http\\' => __DIR__ .
'/libs/http/',
86 'Wikimedia\\Rdbms\\Platform\\' => __DIR__ .
'/libs/rdbms/platform/',
87 'Wikimedia\\UUID\\' => __DIR__ .
'/libs/uuid/',
98 private static $classFiles = [];
109 self::$psr4Namespaces += $dirs;
119 self::$classFiles += $files;
151 public static function loadFiles( array $files ): void {
152 foreach ( $files as $f ) {
153 self::loadFile( $f );
163 public static function find( $className ): ?string {
170 self::$classFiles[$className] ??
174 if ( !$filename && strpos( $className,
'\\' ) !==
false ) {
176 $prefix = $className;
177 while ( ( $pos = strrpos( $prefix,
'\\' ) ) !==
false ) {
179 $prefix = substr( $className, 0, $pos + 1 );
180 if ( isset( self::$psr4Namespaces[$prefix] ) ) {
181 $relativeClass = substr( $className, $pos + 1 );
183 $file = self::$psr4Namespaces[$prefix] .
185 strtr( $relativeClass,
'\\',
'/' ) .
187 if ( is_file(
$file ) ) {
194 $prefix = rtrim( $prefix,
'\\' );
205 if ( $filename[0] !==
'/' && $filename[1] !==
':' ) {
206 $filename = __DIR__ .
'/../' . $filename;
218 $filename = self::find( $className );
220 if ( $filename !==
null ) {
221 require_once $filename;
226 private static function assertTesting( $method ) {
227 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
228 throw new LogicException(
"$method is not supported outside phpunit tests!" );
240 self::assertTesting( __METHOD__ );
256 self::assertTesting( __METHOD__ );
257 return self::$psr4Namespaces;
268 self::assertTesting( __METHOD__ );
270 'classFiles' => self::$classFiles,
271 'psr4Namespaces' => self::$psr4Namespaces,
284 self::assertTesting( __METHOD__ );
286 self::$classFiles = $state[
'classFiles'];
287 self::$psr4Namespaces = $state[
'psr4Namespaces'];
292spl_autoload_register( [
'AutoLoader',
'autoload' ] );
295if ( is_readable( __DIR__ .
'/../vendor/autoload.php' ) ) {
296 require_once __DIR__ .
'/../vendor/autoload.php';
297} elseif ( file_exists( __DIR__ .
'/../vendor/autoload.php' ) ) {
298 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
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.