MediaWiki REL1_32
|
Accepts a list of files and directories to search for php files and generates $wgAutoloadLocalClasses or $wgAutoloadClasses lines for all detected classes. More...
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. | |
setPsr4Namespaces (array $namespaces) | |
Set PSR4 namespaces. | |
Public Attributes | |
const | FILETYPE_JSON = 'json' |
const | FILETYPE_PHP = 'php' |
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[] | $psr4Namespaces = [] |
Configured PSR4 namespaces. | |
string | $variableName = 'wgAutoloadClasses' |
The global variable to write output to. | |
Private Member Functions | |
shouldExclude ( $path) | |
Whether the file should be excluded. | |
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();
Definition at line 16 of file AutoloadGenerator.php.
AutoloadGenerator::__construct | ( | $basepath, | |
$flags = [] ) |
string | $basepath | Root 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 66 of file AutoloadGenerator.php.
References $basepath, and normalizePathSeparator().
AutoloadGenerator::forceClassPath | ( | $fqcn, | |
$inputPath ) |
Force a class to be autoloaded from a specific path, regardless of where or if it was detected.
string | $fqcn | FQCN to force the location of |
string | $inputPath | Full path to the file containing the class |
Exception |
Definition at line 129 of file AutoloadGenerator.php.
References normalizePathSeparator().
|
protected |
Updates the AutoloadClasses field at the given filename.
string | $filename | Filename of JSON extension/skin registration file |
Definition at line 212 of file AutoloadGenerator.php.
References classes.
Referenced by getAutoload().
|
protected |
Generates a PHP file setting up autoload information.
string | $commandName | Command name to include in comment |
string | $filename | of PHP file to put autoload information in. |
Definition at line 243 of file AutoloadGenerator.php.
References $content, $output, and classes.
Referenced by getAutoload().
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)
string | $commandName | Value used in file comment to direct developers towards the appropriate way to update the autoload. |
Definition at line 302 of file AutoloadGenerator.php.
References $fileinfo, generateJsonAutoload(), generatePHPAutoload(), and getTargetFileinfo().
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.
Definition at line 323 of file AutoloadGenerator.php.
References $fileinfo, FILETYPE_JSON, and FILETYPE_PHP.
Referenced by getAutoload().
AutoloadGenerator::initMediaWikiDefault | ( | ) |
Initialize the source files and directories which are used for the MediaWiki default autoloader in {mw-base-dir}/autoload.php including:
Definition at line 362 of file AutoloadGenerator.php.
References readDir(), and readFile().
|
staticprotected |
Ensure that Unix-style path separators ("/") are used in the path.
string | $path |
Definition at line 349 of file AutoloadGenerator.php.
Referenced by __construct(), forceClassPath(), readFile(), and setExcludePaths().
AutoloadGenerator::readDir | ( | $dir | ) |
string | $dir | Path to a directory to recursively search for php files with either .php or .inc extensions |
Definition at line 190 of file AutoloadGenerator.php.
References $ext, and readFile().
Referenced by initMediaWikiDefault().
AutoloadGenerator::readFile | ( | $inputPath | ) |
string | $inputPath | Path to a php file to find classes within |
Exception |
Definition at line 146 of file AutoloadGenerator.php.
References $result, classes, normalizePathSeparator(), and shouldExclude().
Referenced by initMediaWikiDefault(), and readDir().
AutoloadGenerator::setExcludePaths | ( | array | $paths | ) |
Directories that should be excluded.
string[] | $paths |
Definition at line 83 of file AutoloadGenerator.php.
References normalizePathSeparator().
AutoloadGenerator::setPsr4Namespaces | ( | array | $namespaces | ) |
Set PSR4 namespaces.
Unlike self::setExcludePaths(), this will only skip outputting the autoloader entry when the namespace matches the path.
string[] | $namespaces | Associative array mapping namespace to path |
Definition at line 98 of file AutoloadGenerator.php.
References $namespaces.
|
private |
Whether the file should be excluded.
string | $path | File path |
Definition at line 111 of file AutoloadGenerator.php.
Referenced by readFile().
|
protected |
Root path of the project being scanned for classes.
Definition at line 23 of file AutoloadGenerator.php.
Referenced by __construct().
|
protected |
Map of file shortpath to list of FQCN detected within file.
Definition at line 33 of file AutoloadGenerator.php.
|
protected |
Helper class extracts class names from php files.
Definition at line 28 of file AutoloadGenerator.php.
|
protected |
Directories that should be excluded.
Definition at line 50 of file AutoloadGenerator.php.
|
protected |
Map of FQCN to relative path(from self::$basepath)
Definition at line 43 of file AutoloadGenerator.php.
|
protected |
|
protected |
The global variable to write output to.
Definition at line 38 of file AutoloadGenerator.php.
const AutoloadGenerator::FILETYPE_JSON = 'json' |
Definition at line 17 of file AutoloadGenerator.php.
Referenced by getTargetFileinfo().
const AutoloadGenerator::FILETYPE_PHP = 'php' |
Definition at line 18 of file AutoloadGenerator.php.
Referenced by getTargetFileinfo().