25 yield [ $prefix, $dir,
$file ];
31 return (
new File_Iterator_Facade() )->getFilesAsArray( $dir, [
'.php' ] );
39 $contents = file_get_contents(
$file );
41 $classes = array_keys( $classesInFile );
46 "Only one class per file in PSR-4 autoloaded classes ($file)"
52 $abbrFileName = substr( substr(
$file, strlen( $dir ) ), 0, -4 );
53 $expectedClassName = $prefix . str_replace(
'/',
'\\', $abbrFileName );
58 "Class not autoloaded properly"
64 $this->assertCount( 0, $classes );
67 if ( $aliasesInFile ) {
69 foreach ( $aliasesInFile
as $alias => $class ) {
70 $this->assertArrayHasKey( $alias, $otherClasses,
71 'Alias must be in the classmap autoloader'
83 (?:final\s+)? (?:abstract\s+)? (?:class|interface|trait) \s+
86 class_alias \s* \( \s*
87 ([\'"]) (?P<original> [^\'"]+) \g{-2} \s* , \s*
88 ([\'"]) (?P<alias> [^\'"]+ ) \g{-2} \s*
91 class_alias \s* \( \s*
92 (?P<originalStatic> [\w\\\\]+)::class \s* , \s*
93 ([\'"]) (?P<aliasString> [^\'"]+ ) \g{-2} \s*
96 /imx', $contents,
$matches, PREG_SET_ORDER );
104 /imx', $contents, $namespaceMatch );
105 $fileNamespace = $namespaceMatch ? $namespaceMatch[1] .
'\\' :
'';
111 if ( !empty( $match[
'class'] ) ) {
113 $class = $fileNamespace . $match[
'class'];
114 $classesInFile[$class] =
true;
115 } elseif ( !empty( $match[
'original'] ) ) {
117 $aliasesInFile[$match[
'alias']] = $match[
'original'];
120 $aliasesInFile[$match[
'aliasString']] = $fileNamespace . $match[
'originalStatic'];
124 return [ $classesInFile, $aliasesInFile ];
134 $psr4Namespaces = [];
136 $psr4Namespaces[rtrim( $ns,
'\\' ) .
'\\'] = rtrim(
$path,
'/' );
139 foreach ( $expected
as $class =>
$file ) {
142 if ( substr(
$file, 0, 1 ) !=
'/' && substr(
$file, 1, 1 ) !=
':' ) {
143 $filePath =
"$IP/$file";
148 if ( !file_exists( $filePath ) ) {
149 $actual[$class] =
"[file '$filePath' does not exist]";
153 Wikimedia\suppressWarnings();
154 $contents = file_get_contents( $filePath );
155 Wikimedia\restoreWarnings();
157 if ( $contents ===
false ) {
158 $actual[$class] =
"[couldn't read file '$filePath']";
164 foreach ( $classesInFile
as $className => $ignore ) {
166 $parts = explode(
'\\', $className );
167 for ( $i = count( $parts ) - 1; $i > 0; $i-- ) {
168 $ns = implode(
'\\', array_slice( $parts, 0, $i ) ) .
'\\';
169 if ( isset( $psr4Namespaces[$ns] ) ) {
170 $expectedPath = $psr4Namespaces[$ns] .
'/'
171 . implode(
'/', array_slice( $parts, $i ) )
173 if ( $filePath === $expectedPath ) {
180 $actual[$className] =
$file;
186 foreach ( $aliasesInFile
as $alias => $class ) {
187 if ( isset( $classesInFile[$class] ) ) {
188 $actual[$alias] =
$file;
190 $actual[$alias] =
"[original class not in $file]";
196 'expected' => $expected,
202 $path = realpath( __DIR__ .
'/../../..' );
203 $oldAutoload = file_get_contents(
$path .
'/autoload.php' );
207 $newAutoload =
$generator->getAutoload(
'maintenance/generateLocalAutoload.php' );
209 $this->assertEquals( $oldAutoload, $newAutoload,
'autoload.php does not match' .
210 ' output of generateLocalAutoload.php script.' );
$wgAutoloadClasses
Array mapping class names to filenames, for autoloading.
global $wgAutoloadLocalClasses
testAutoLoadConfig()
Assert that there were no classes loaded that are not registered with the AutoLoader.
providePSR4Completeness()
static checkAutoLoadConf()
testPSR4Completeness( $prefix, $dir, $file)
providePSR4Completeness
static parseFile( $contents)
static getAutoloadNamespaces()
Get a mapping of namespace => file path The namespaces should follow the PSR-4 standard for autoloadi...
static string[] $psr4Namespaces
Accepts a list of files and directories to search for php files and generates $wgAutoloadLocalClasses...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file