MediaWiki  1.29.2
AutoLoader.php
Go to the documentation of this file.
1 <?php
28 require_once __DIR__ . '/../autoload.php';
29 
30 class AutoLoader {
31  static protected $autoloadLocalClassesLower = null;
32 
38  static function autoload( $className ) {
40  $wgAutoloadAttemptLowercase;
41 
42  $filename = false;
43 
44  if ( isset( $wgAutoloadLocalClasses[$className] ) ) {
45  $filename = $wgAutoloadLocalClasses[$className];
46  } elseif ( isset( $wgAutoloadClasses[$className] ) ) {
47  $filename = $wgAutoloadClasses[$className];
48  } elseif ( $wgAutoloadAttemptLowercase ) {
49  /*
50  * Try a different capitalisation.
51  *
52  * PHP 4 objects are always serialized with the classname coerced to lowercase,
53  * and we are plagued with several legacy uses created by MediaWiki < 1.5, see
54  * https://wikitech.wikimedia.org/wiki/Text_storage_data
55  */
56  $lowerClass = strtolower( $className );
57 
58  if ( self::$autoloadLocalClassesLower === null ) {
59  self::$autoloadLocalClassesLower = array_change_key_case( $wgAutoloadLocalClasses, CASE_LOWER );
60  }
61 
62  if ( isset( self::$autoloadLocalClassesLower[$lowerClass] ) ) {
63  if ( function_exists( 'wfDebugLog' ) ) {
64  wfDebugLog( 'autoloader', "Class {$className} was loaded using incorrect case" );
65  }
66  $filename = self::$autoloadLocalClassesLower[$lowerClass];
67  }
68  }
69 
70  if ( !$filename ) {
71  // Class not found; let the next autoloader try to find it
72  return;
73  }
74 
75  // Make an absolute path, this improves performance by avoiding some stat calls
76  if ( substr( $filename, 0, 1 ) != '/' && substr( $filename, 1, 1 ) != ':' ) {
77  global $IP;
78  $filename = "$IP/$filename";
79  }
80 
81  require $filename;
82  }
83 
88  static function resetAutoloadLocalClassesLower() {
89  self::$autoloadLocalClassesLower = null;
90  }
91 }
92 
93 spl_autoload_register( [ 'AutoLoader', 'autoload' ] );
$wgAutoloadClasses
global $wgAutoloadClasses
Definition: TestsAutoLoader.php:24
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1092
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
AutoLoader
Locations of core classes Extension classes are specified with $wgAutoloadClasses This array is a glo...
Definition: AutoLoader.php:30
AutoLoader\resetAutoloadLocalClassesLower
static resetAutoloadLocalClassesLower()
Method to clear the protected class property $autoloadLocalClassesLower.
Definition: AutoLoader.php:88
$IP
$IP
Definition: update.php:3
$wgAutoloadLocalClasses
global $wgAutoloadLocalClasses
Definition: autoload.php:4
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
AutoLoader\$autoloadLocalClassesLower
static $autoloadLocalClassesLower
Definition: AutoLoader.php:31
AutoLoader\autoload
static autoload( $className)
autoload - take a class name and attempt to load it
Definition: AutoLoader.php:38