13require_once __DIR__ .
'/../autoload.php';
44 private static $psr4Namespaces = [];
49 private static $classFiles = [];
60 self::$psr4Namespaces += $dirs;
70 self::$classFiles += $files;
89 public static function loadFile(
string $file ): void {
102 public static function loadFiles( array $files ): void {
103 foreach ( $files as $f ) {
104 self::loadFile( $f );
114 public static function find( $className ): ?string {
121 self::$classFiles[$className] ??
125 if ( !$filename && str_contains( $className,
'\\' ) ) {
127 $prefix = $className;
129 while ( ( $pos = strrpos( $prefix,
'\\' ) ) !==
false ) {
131 $prefix = substr( $className, 0, $pos + 1 );
132 if ( isset( self::$psr4Namespaces[$prefix] ) ) {
133 $relativeClass = substr( $className, $pos + 1 );
135 $file = self::$psr4Namespaces[$prefix] .
136 strtr( $relativeClass,
'\\',
'/' ) .
138 if ( is_file( $file ) ) {
145 $prefix = rtrim( $prefix,
'\\' );
156 if ( $filename[0] !==
'/' && $filename[1] !==
':' ) {
157 $filename = __DIR__ .
'/../' . $filename;
169 $filename = self::find( $className );
171 if ( $filename !==
null ) {
172 require_once $filename;
177 private static function assertTesting(
string $method ): void {
178 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
179 throw new LogicException(
"$method is not supported outside phpunit tests!" );
191 self::assertTesting( __METHOD__ );
207 self::assertTesting( __METHOD__ );
208 return self::$psr4Namespaces;
219 self::assertTesting( __METHOD__ );
221 'classFiles' => self::$classFiles,
222 'psr4Namespaces' => self::$psr4Namespaces,
235 self::assertTesting( __METHOD__ );
237 self::$classFiles = $state[
'classFiles'];
238 self::$psr4Namespaces = $state[
'psr4Namespaces'];
243spl_autoload_register( AutoLoader::autoload( ... ) );
246if ( is_readable( __DIR__ .
'/../vendor/autoload.php' ) ) {
247 require_once __DIR__ .
'/../vendor/autoload.php';
248} elseif ( file_exists( __DIR__ .
'/../vendor/autoload.php' ) ) {
249 die( __DIR__ .
'/../vendor/autoload.php exists but is not readable' );
if(!defined('MW_SETUP_CALLBACK'))
global $wgAutoloadLocalClasses
This initializes autoloading for MediaWiki core, extensions, and vendored libraries.
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.
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