MediaWiki  1.27.2
AutoloadGenerator Class Reference

Accepts a list of files and directories to search for php files and generates $wgAutoloadLocalClasses or $wgAutoloadClasses lines for all detected classes. More...

Collaboration diagram for 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. More...
 
 generateAutoload ($commandName= 'AutoloadGenerator')
 Write out all known classes to autoload.php, extension.json, or skin.json in the provided basedir. More...
 
 readDir ($dir)
 
 readFile ($inputPath)
 

Protected Member Functions

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

Static Protected Member Functions

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

Protected Attributes

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

Detailed Description

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->generateAutoload();

Definition at line 16 of file AutoloadGenerator.php.

Constructor & Destructor Documentation

AutoloadGenerator::__construct (   $basepath,
  $flags = [] 
)
Parameters
string$basepathRoot path of the project being scanned for classes
array | string$flagslocal - If this flag is set $wgAutoloadLocalClasses will be build instead of $wgAutoloadClasses

Definition at line 49 of file AutoloadGenerator.php.

References $flags.

Member Function Documentation

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
Exception

Definition at line 68 of file AutoloadGenerator.php.

References $path.

AutoloadGenerator::generateAutoload (   $commandName = 'AutoloadGenerator')

Write out all known classes to autoload.php, extension.json, or skin.json in the provided basedir.

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

Definition at line 225 of file AutoloadGenerator.php.

References generateJsonAutoload(), and generatePHPAutoload().

AutoloadGenerator::generateJsonAutoload (   $filename)
protected

Updates the AutoloadClasses field at the given filename.

Parameters
{string}$filename Filename of JSON extension/skin registration file

Definition at line 128 of file AutoloadGenerator.php.

References $key, $path, as, classes, FormatJson\decode(), and FormatJson\encode().

Referenced by generateAutoload().

AutoloadGenerator::generatePHPAutoload (   $commandName,
  $filename 
)
protected

Generates a PHP file setting up autoload information.

Parameters
{string}$commandName Command name to include in comment
{string}$filename of PHP file to put autoload information in.

Definition at line 163 of file AutoloadGenerator.php.

References $content, $output, $path, as, classes, global, and php.

Referenced by generateAutoload().

static AutoloadGenerator::normalizePathSeparator (   $path)
staticprotected

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

Parameters
string$path
Returns
string

Definition at line 249 of file AutoloadGenerator.php.

References $path.

AutoloadGenerator::readDir (   $dir)
Parameters
string$dirPath to a directory to recursively search for php files with either .php or .inc extensions

Definition at line 107 of file AutoloadGenerator.php.

References $dir, $ext, $path, as, and readFile().

AutoloadGenerator::readFile (   $inputPath)
Parameters
string$inputPathPath to a php file to find classes within
Exceptions
Exception

Definition at line 85 of file AutoloadGenerator.php.

References classes.

Referenced by readDir().

Member Data Documentation

string AutoloadGenerator::$basepath
protected

Root path of the project being scanned for classes.

Definition at line 20 of file AutoloadGenerator.php.

array AutoloadGenerator::$classes = []
protected

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

Definition at line 30 of file AutoloadGenerator.php.

ClassCollector AutoloadGenerator::$collector
protected

Helper class extracts class names from php files.

Definition at line 25 of file AutoloadGenerator.php.

array AutoloadGenerator::$overrides = []
protected

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

Definition at line 40 of file AutoloadGenerator.php.

string AutoloadGenerator::$variableName = 'wgAutoloadClasses'
protected

The global variable to write output to.

Definition at line 35 of file AutoloadGenerator.php.


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