60 if ( !is_array( $flags ) ) {
65 if ( in_array(
'local', $flags ) ) {
66 $this->variableName =
'wgAutoloadLocalClasses';
77 foreach ( $paths as $path ) {
89 foreach ( $this->excludePaths as $dir ) {
90 if ( strpos( $path, $dir ) === 0 ) {
109 throw new \Exception(
"Invalid path: $inputPath" );
111 $len = strlen( $this->basepath );
112 if ( substr( $path, 0, $len ) !== $this->basepath ) {
113 throw new \Exception(
"Path is not within basepath: $inputPath" );
115 $shortpath = substr( $path, $len );
116 $this->overrides[$fqcn] = $shortpath;
128 $len = strlen( $this->basepath );
129 if ( substr( $inputPath, 0, $len ) !== $this->basepath ) {
130 throw new \Exception(
"Path is not within basepath: $inputPath" );
135 $result = $this->collector->getClasses(
136 file_get_contents( $inputPath )
139 $shortpath = substr( $inputPath, $len );
149 $it =
new RecursiveDirectoryIterator(
150 self::normalizePathSeparator( realpath( $dir ) ) );
151 $it =
new RecursiveIteratorIterator( $it );
153 foreach ( $it as $path => $file ) {
154 $ext = pathinfo( $path, PATHINFO_EXTENSION );
156 if (
$ext ===
'php' ||
$ext ===
'inc' ) {
171 $key =
'AutoloadClasses';
172 $json = FormatJson::decode( file_get_contents( $filename ),
true );
173 unset( $json[$key] );
176 foreach ( $this->
classes as $path => $contained ) {
177 foreach ( $contained as $fqcn ) {
179 $json[$key][$fqcn] = substr( $path, 1 );
182 foreach ( $this->overrides as $path => $fqcn ) {
184 $json[$key][$fqcn] = substr( $path, 1 );
188 ksort( $json[$key] );
191 return FormatJson::encode( $json,
"\t", FormatJson::ALL_OK ) .
"\n";
207 $format =
"%s => __DIR__ . %s,";
208 foreach ( $this->
classes as $path => $contained ) {
209 $exportedPath = var_export( $path,
true );
210 foreach ( $contained as $fqcn ) {
211 $content[$fqcn] = sprintf(
213 var_export( $fqcn,
true ),
219 foreach ( $this->overrides as $fqcn => $path ) {
220 $content[$fqcn] = sprintf(
222 var_export( $fqcn,
true ),
223 var_export( $path,
true )
232 if ( $this->variableName ===
'wgAutoloadClasses' ) {
238 $output = implode(
"\n\t", $content );
243global \${$this->variableName};
245\${$this->variableName} {$op} [
260 public function getAutoload( $commandName =
'AutoloadGenerator' ) {
266 if (
$fileinfo[
'type'] === self::FILETYPE_JSON ) {
283 'filename' => $this->basepath .
'/autoload.php',
286 if ( file_exists( $this->basepath .
'/extension.json' ) ) {
288 'filename' => $this->basepath .
'/extension.json',
291 } elseif ( file_exists( $this->basepath .
'/skin.json' ) ) {
293 'filename' => $this->basepath .
'/skin.json',
308 return str_replace(
'\\',
'/', $path );
321 foreach ( [
'includes',
'languages',
'maintenance',
'mw-config' ] as $dir ) {
322 $this->
readDir( $this->basepath .
'/' . $dir );
324 foreach ( glob( $this->basepath .
'/*.php' ) as $file ) {
365 $this->
namespace = '';
367 $this->startToken =
null;
371 foreach ( token_get_all(
$code ) as $token ) {
372 if ( $this->startToken ===
null ) {
388 if ( is_string( $token ) ) {
393 switch ( $token[0] ) {
399 $this->startToken = $token;
402 if ( $token[1] ===
'class_alias' ) {
403 $this->startToken = $token;
415 switch ( $this->startToken[0] ) {
419 $this->startToken =
null;
422 if ( $token ===
';' || $token ===
'{' ) {
425 $this->tokens[] = $token;
430 if ( $this->alias !==
null ) {
449 if ( $token ===
'(' ) {
451 $this->alias = [
'target' =>
false,
'name' =>
false ];
452 } elseif ( $token ===
',' ) {
454 if ( $this->alias[
'target'] ===
false ) {
455 $this->alias[
'target'] =
true;
457 } elseif ( is_array( $token ) && $token[0] === T_CONSTANT_ENCAPSED_STRING ) {
458 if ( $this->alias[
'target'] ===
true ) {
461 $this->alias[
'name'] = substr( $token[1], 1, -1 );
463 } elseif ( $token ===
')' ) {
465 $this->
classes[] = $this->alias[
'name'];
467 $this->startToken =
null;
468 } elseif ( !is_array( $token ) || (
469 $token[0] !== T_STRING &&
470 $token[0] !== T_DOUBLE_COLON &&
471 $token[0] !== T_CLASS &&
472 $token[0] !== T_WHITESPACE
476 $this->startToken =
null;
484 $this->tokens[] = $token;
485 if ( is_array( $token ) && $token[0] === T_STRING ) {
499 foreach ( $this->tokens as $token ) {
500 $content[] = is_string( $token ) ? $token : $token[1];
504 $this->startToken =
null;
506 return trim( implode(
'', $content ),
" \n\t" );
Accepts a list of files and directories to search for php files and generates $wgAutoloadLocalClasses...
shouldExclude( $path)
Whether the file should be excluded.
string $basepath
Root path of the project being scanned for classes.
setExcludePaths(array $paths)
Directories that should be excluded.
getTargetFileinfo()
Returns the filename of the extension.json of skin.json, if there's any, or otherwise the path to the...
generateJsonAutoload( $filename)
Updates the AutoloadClasses field at the given filename.
__construct( $basepath, $flags=[])
getAutoload( $commandName='AutoloadGenerator')
Returns all known classes as a string, which can be used to put into a target file (e....
forceClassPath( $fqcn, $inputPath)
Force a class to be autoloaded from a specific path, regardless of where or if it was detected.
array $classes
Map of file shortpath to list of FQCN detected within file.
generatePHPAutoload( $commandName, $filename)
Generates a PHP file setting up autoload information.
string $variableName
The global variable to write output to.
initMediaWikiDefault()
Initialize the source files and directories which are used for the MediaWiki default autoloader in {m...
ClassCollector $collector
Helper class extracts class names from php files.
string[] $excludePaths
Directories that should be excluded.
static normalizePathSeparator( $path)
Ensure that Unix-style path separators ("/") are used in the path.
array $overrides
Map of FQCN to relative path(from self::$basepath)
Reads PHP code and returns the FQCN of every class defined within it.
implodeTokens()
Returns the string representation of the tokens within the current expect sequence and resets the seq...
string $namespace
Current namespace.
array $classes
List of FQCN detected in this pass.
tryEndExpect( $token)
Accepts the next token in an expect sequence.
array $startToken
Token from token_get_all() that started an expect sequence.
tryBeginExpect( $token)
Determine if $token begins the next expect sequence.
array $alias
Class alias with target/name fields.
array $tokens
List of tokens that are members of the current expect sequence.
namespace being checked & $result
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
processing should stop and the error should be shown to the user * false
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the classes
if(!is_readable( $file)) $ext