X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FAutoLoader.php;h=62b1d39f3c17a3d0d12bd0db76d4c95c3bb14b95;hb=386bd27f6449b8e68b65a7267498b803d05970ae;hp=8dc7d4094a0b983237996173637c9bff89a61bd7;hpb=57eaa2bf04ce1b48bd89c10defe4de5b7d31f047;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 8dc7d4094a..62b1d39f3c 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -30,6 +30,12 @@ require_once __DIR__ . '/../autoload.php'; class AutoLoader { static protected $autoloadLocalClassesLower = null; + /** + * @private Only public for ExtensionRegistry + * @var string[] Namespace (ends with \) => Path (ends with /) + */ + static public $psr4Namespaces = []; + /** * autoload - take a class name and attempt to load it * @@ -67,6 +73,28 @@ class AutoLoader { } } + if ( !$filename && strpos( $className, '\\' ) !== false ) { + // This class is namespaced, so try looking at the namespace map + $prefix = $className; + while ( false !== $pos = strrpos( $prefix, '\\' ) ) { + // Check to see if this namespace prefix is in the map + $prefix = substr( $className, 0, $pos + 1 ); + if ( isset( self::$psr4Namespaces[$prefix] ) ) { + $relativeClass = substr( $className, $pos + 1 ); + // Build the expected filename, and see if it exists + $file = self::$psr4Namespaces[$prefix] . '/' . + str_replace( '\\', '/', $relativeClass ) . '.php'; + if ( file_exists( $file ) ) { + $filename = $file; + break; + } + } + + // Remove trailing separator for next iteration + $prefix = rtrim( $prefix, '\\' ); + } + } + if ( !$filename ) { // Class not found; let the next autoloader try to find it return; @@ -88,6 +116,31 @@ class AutoLoader { static function resetAutoloadLocalClassesLower() { self::$autoloadLocalClassesLower = null; } + + /** + * Get a mapping of namespace => file path + * The namespaces should follow the PSR-4 standard for autoloading + * + * @see + * @private Only public for usage in AutoloadGenerator + * @since 1.31 + * @return string[] + */ + public static function getAutoloadNamespaces() { + return [ + 'MediaWiki\\Edit\\' => __DIR__ . '/edit/', + 'MediaWiki\\EditPage\\' => __DIR__ . '/editpage/', + 'MediaWiki\\Linker\\' => __DIR__ .'/linker/', + 'MediaWiki\\Preferences\\' => __DIR__ .'/preferences/', + 'MediaWiki\\Services\\' => __DIR__ .'/services/', + 'MediaWiki\\Session\\' => __DIR__ .'/session/', + 'MediaWiki\\Shell\\' => __DIR__ .'/shell/', + 'MediaWiki\\Sparql\\' => __DIR__ .'/sparql/', + 'MediaWiki\\Storage\\' => __DIR__ .'/Storage/', + 'MediaWiki\\Tidy\\' => __DIR__ .'/tidy/', + ]; + } } +AutoLoader::$psr4Namespaces = AutoLoader::getAutoloadNamespaces(); spl_autoload_register( [ 'AutoLoader', 'autoload' ] );