MediaWiki master
MediaWiki\Autoload\AutoloadGenerator Class Reference

Scan given directories and files and create an autoload class map. More...

Collaboration diagram for MediaWiki\Autoload\AutoloadGenerator:

Public Member Functions

 __construct ( $basepath, $flags=[])
 
 forceClassPath ( $fqcn, $inputPath)
 Force a class to be autoloaded from a specific path, regardless of where or if it was detected.
 
 getAutoload ( $commandName='AutoloadGenerator')
 Returns all known classes as a string, which can be used to put into a target file (e.g.
 
 getTargetFileinfo ()
 Returns the filename of the extension.json of skin.json, if there's any, or otherwise the path to the autoload.php file in an array as the "filename" key and with the type (AutoloadGenerator::FILETYPE_JSON or AutoloadGenerator::FILETYPE_PHP) of the file as the "type" key.
 
 initMediaWikiDefault ()
 Initialize the source files and directories which are used for the MediaWiki default autoloader in {mw-base-dir}/autoload.php including:
 
 readDir ( $dir)
 
 readFile ( $inputPath)
 
 setExcludePaths (array $paths)
 Directories that should be excluded.
 

Protected Member Functions

 generateJsonAutoload ( $filename)
 Updates the AutoloadClasses field at the given filename.
 
 generatePHPAutoload ( $commandName, $filename)
 Generates a PHP file setting up autoload information.
 

Static Protected Member Functions

static normalizePathSeparator ( $path)
 Ensure that Unix-style path separators ("/") are used in the path.
 

Protected Attributes

string $basepath
 Root path of the project being scanned for classes.
 
array $classes = []
 Map of file shortpath to list of FQCN detected within file.
 
ClassCollector $collector
 Helper class extracts class names from php files.
 
string[] $excludePaths = []
 Directories that should be excluded.
 
array $overrides = []
 Map of FQCN to relative path(from self::$basepath)
 
string $variableName = 'wgAutoloadClasses'
 The global variable to write output to.
 

Detailed Description

Scan given directories and files and create an autoload class map.

Accepts a list of files and directories to search for php files and generates $wgAutoloadLocalClasses or $wgAutoloadClasses lines for all detected classes. These lines are written out to an autoload.php file in the projects provided basedir.

Usage:

$gen = new AutoloadGenerator( __DIR__ );
$gen->readDir( __DIR__ . '/includes' );
$gen->readFile( __DIR__ . '/foo.php' )
$gen->getAutoload();
See also
\MediaWiki\Maintenance\Maintenance\GenerateAutoload
Since
1.25

Definition at line 33 of file AutoloadGenerator.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Autoload\AutoloadGenerator::__construct ( $basepath,
$flags = [] )
Parameters
string$basepathRoot path of the project being scanned for classes
array | string$flags

local - If this flag is set $wgAutoloadLocalClasses will be build instead of $wgAutoloadClasses

Definition at line 76 of file AutoloadGenerator.php.

References MediaWiki\Autoload\AutoloadGenerator\$basepath, and MediaWiki\Autoload\AutoloadGenerator\normalizePathSeparator().

Member Function Documentation

◆ forceClassPath()

MediaWiki\Autoload\AutoloadGenerator::forceClassPath ( $fqcn,
$inputPath )

Force a class to be autoloaded from a specific path, regardless of where or if it was detected.

Parameters
string$fqcnFQCN to force the location of
string$inputPathFull path to the file containing the class
Exceptions
InvalidArgumentException

Definition at line 123 of file AutoloadGenerator.php.

References $path, and MediaWiki\Autoload\AutoloadGenerator\normalizePathSeparator().

◆ generateJsonAutoload()

MediaWiki\Autoload\AutoloadGenerator::generateJsonAutoload ( $filename)
protected

Updates the AutoloadClasses field at the given filename.

Parameters
string$filenameFilename of JSON extension/skin registration file
Returns
string Updated Json of the file given as the $filename parameter

Definition at line 197 of file AutoloadGenerator.php.

References $path.

Referenced by MediaWiki\Autoload\AutoloadGenerator\getAutoload().

◆ generatePHPAutoload()

MediaWiki\Autoload\AutoloadGenerator::generatePHPAutoload ( $commandName,
$filename )
protected

Generates a PHP file setting up autoload information.

Parameters
string$commandNameCommand name to include in comment
string$filenameof PHP file to put autoload information in.
Returns
string

Definition at line 228 of file AutoloadGenerator.php.

References $path.

Referenced by MediaWiki\Autoload\AutoloadGenerator\getAutoload().

◆ getAutoload()

MediaWiki\Autoload\AutoloadGenerator::getAutoload ( $commandName = 'AutoloadGenerator')

Returns all known classes as a string, which can be used to put into a target file (e.g.

extension.json, skin.json or autoload.php)

Parameters
string$commandNameValue used in file comment to direct developers towards the appropriate way to update the autoload.
Returns
string

Definition at line 287 of file AutoloadGenerator.php.

References MediaWiki\Autoload\AutoloadGenerator\generateJsonAutoload(), MediaWiki\Autoload\AutoloadGenerator\generatePHPAutoload(), and MediaWiki\Autoload\AutoloadGenerator\getTargetFileinfo().

◆ getTargetFileinfo()

MediaWiki\Autoload\AutoloadGenerator::getTargetFileinfo ( )

Returns the filename of the extension.json of skin.json, if there's any, or otherwise the path to the autoload.php file in an array as the "filename" key and with the type (AutoloadGenerator::FILETYPE_JSON or AutoloadGenerator::FILETYPE_PHP) of the file as the "type" key.

Returns
array

Definition at line 308 of file AutoloadGenerator.php.

Referenced by MediaWiki\Autoload\AutoloadGenerator\getAutoload().

◆ initMediaWikiDefault()

MediaWiki\Autoload\AutoloadGenerator::initMediaWikiDefault ( )

Initialize the source files and directories which are used for the MediaWiki default autoloader in {mw-base-dir}/autoload.php including:

  • includes/
  • languages/
  • maintenance/
  • mw-config/
  • any *.php file in the base directory

Definition at line 347 of file AutoloadGenerator.php.

References MediaWiki\Autoload\AutoloadGenerator\readDir(), and MediaWiki\Autoload\AutoloadGenerator\readFile().

◆ normalizePathSeparator()

static MediaWiki\Autoload\AutoloadGenerator::normalizePathSeparator ( $path)
staticprotected

Ensure that Unix-style path separators ("/") are used in the path.

Parameters
string$path
Returns
string

Definition at line 334 of file AutoloadGenerator.php.

References $path.

Referenced by MediaWiki\Autoload\AutoloadGenerator\__construct(), MediaWiki\Autoload\AutoloadGenerator\forceClassPath(), MediaWiki\Autoload\AutoloadGenerator\readFile(), and MediaWiki\Autoload\AutoloadGenerator\setExcludePaths().

◆ readDir()

MediaWiki\Autoload\AutoloadGenerator::readDir ( $dir)
Parameters
string$dirPath to a directory to recursively search for php files

Definition at line 177 of file AutoloadGenerator.php.

References $path, and MediaWiki\Autoload\AutoloadGenerator\readFile().

Referenced by MediaWiki\Autoload\AutoloadGenerator\initMediaWikiDefault().

◆ readFile()

MediaWiki\Autoload\AutoloadGenerator::readFile ( $inputPath)
Parameters
string$inputPathPath to a php file to find classes within
Exceptions
InvalidArgumentException

Definition at line 139 of file AutoloadGenerator.php.

References MediaWiki\Autoload\AutoloadGenerator\normalizePathSeparator().

Referenced by MediaWiki\Autoload\AutoloadGenerator\initMediaWikiDefault(), and MediaWiki\Autoload\AutoloadGenerator\readDir().

◆ setExcludePaths()

MediaWiki\Autoload\AutoloadGenerator::setExcludePaths ( array $paths)

Directories that should be excluded.

Since
1.31
Parameters
string[]$paths

Definition at line 93 of file AutoloadGenerator.php.

References $path, and MediaWiki\Autoload\AutoloadGenerator\normalizePathSeparator().

Member Data Documentation

◆ $basepath

string MediaWiki\Autoload\AutoloadGenerator::$basepath
protected

Root path of the project being scanned for classes.

Definition at line 40 of file AutoloadGenerator.php.

Referenced by MediaWiki\Autoload\AutoloadGenerator\__construct().

◆ $classes

array MediaWiki\Autoload\AutoloadGenerator::$classes = []
protected

Map of file shortpath to list of FQCN detected within file.

Definition at line 50 of file AutoloadGenerator.php.

◆ $collector

ClassCollector MediaWiki\Autoload\AutoloadGenerator::$collector
protected

Helper class extracts class names from php files.

Definition at line 45 of file AutoloadGenerator.php.

◆ $excludePaths

string [] MediaWiki\Autoload\AutoloadGenerator::$excludePaths = []
protected

Directories that should be excluded.

Definition at line 67 of file AutoloadGenerator.php.

◆ $overrides

array MediaWiki\Autoload\AutoloadGenerator::$overrides = []
protected

Map of FQCN to relative path(from self::$basepath)

Definition at line 60 of file AutoloadGenerator.php.

◆ $variableName

string MediaWiki\Autoload\AutoloadGenerator::$variableName = 'wgAutoloadClasses'
protected

The global variable to write output to.

Definition at line 55 of file AutoloadGenerator.php.


The documentation for this class was generated from the following file: