73 $this->variableName =
'wgAutoloadLocalClasses';
84 foreach ( $paths as $path ) {
100 $ns =
rtrim( $ns,
'\\' ) .
'\\';
101 $this->psr4Namespaces[$ns] =
rtrim( self::normalizePathSeparator( $path ),
'/' );
112 foreach ( $this->excludePaths as $dir ) {
113 if (
strpos( $path, $dir ) === 0 ) {
134 $len =
strlen( $this->basepath );
135 if (
substr( $path, 0, $len ) !== $this->basepath ) {
136 throw new \Exception(
"Path is not within basepath: $inputPath" );
138 $shortpath =
substr( $path, $len );
151 $len =
strlen( $this->basepath );
152 if (
substr( $inputPath, 0, $len ) !== $this->basepath ) {
153 throw new \Exception(
"Path is not within basepath: $inputPath" );
158 $result = $this->collector->getClasses(
163 $result =
array_filter( $result,
function ( $class ) use ( $inputPath ) {
164 $parts = explode(
'\\', $class );
165 for ( $i = count( $parts ) - 1; $i > 0; $i-- ) {
166 $ns = implode(
'\\',
array_slice( $parts, 0, $i ) ) .
'\\';
167 if (
isset( $this->psr4Namespaces[$ns] ) ) {
168 $expectedPath = $this->psr4Namespaces[$ns] .
'/'
171 if ( $inputPath === $expectedPath ) {
181 $shortpath =
substr( $inputPath, $len );
192 self::normalizePathSeparator( realpath( $dir ) ) );
195 foreach ( $it as $path => $file ) {
198 if (
$ext ===
'php' ||
$ext ===
'inc' ) {
213 $key =
'AutoloadClasses';
215 unset( $json[$key] );
218 foreach ( $this->
classes as $path => $contained ) {
219 foreach ( $contained as $fqcn ) {
224 foreach ( $this->overrides as $path => $fqcn ) {
230 ksort( $json[$key] );
233 return FormatJson::encode( $json,
"\t", FormatJson::ALL_OK ) .
"\n";
249 $format =
"%s => __DIR__ . %s,";
250 foreach ( $this->
classes as $path => $contained ) {
252 foreach ( $contained as $fqcn ) {
261 foreach ( $this->overrides as $fqcn => $path ) {
274 if ( $this->variableName ===
'wgAutoloadClasses' ) {
287\${$this->variableName} {$op} [
302 public function getAutoload( $commandName =
'AutoloadGenerator' ) {
308 if (
$fileinfo[
'type'] === self::FILETYPE_JSON ) {
325 'filename' => $this->basepath .
'/autoload.php',
328 if (
file_exists( $this->basepath .
'/extension.json' ) ) {
330 'filename' => $this->basepath .
'/extension.json',
335 'filename' => $this->basepath .
'/skin.json',
363 foreach ( [
'includes',
'languages',
'maintenance',
'mw-config' ] as $dir ) {
364 $this->
readDir( $this->basepath .
'/' . $dir );
366 foreach (
glob( $this->basepath .
'/*.php' ) as $file ) {
407 $this->
namespace = '';
409 $this->startToken =
null;
414 if ( $this->startToken ===
null ) {
435 switch ( $token[0] ) {
442 $this->startToken = $token;
445 if ( $token[1] ===
'class_alias' ) {
446 $this->startToken = $token;
458 switch ( $this->startToken[0] ) {
462 $this->startToken =
null;
466 if ( !
is_array( $token ) || $token[0] !== T_WHITESPACE ) {
467 $this->startToken =
null;
471 if ( $token ===
';' || $token ===
'{' ) {
474 $this->tokens[] = $token;
479 if ( $this->alias !==
null ) {
498 if ( $token ===
'(' ) {
500 $this->alias = [
'target' =>
false,
'name' =>
false ];
501 }
elseif ( $token ===
',' ) {
503 if ( $this->alias[
'target'] ===
false ) {
504 $this->alias[
'target'] =
true;
506 }
elseif (
is_array( $token ) && $token[0] === T_CONSTANT_ENCAPSED_STRING ) {
507 if ( $this->alias[
'target'] ===
true ) {
510 $this->alias[
'name'] =
substr( $token[1], 1, -1 );
512 }
elseif ( $token ===
')' ) {
514 $this->
classes[] = $this->alias[
'name'];
516 $this->startToken =
null;
518 $token[0] !== T_STRING &&
519 $token[0] !== T_DOUBLE_COLON &&
520 $token[0] !== T_CLASS &&
521 $token[0] !== T_WHITESPACE
525 $this->startToken =
null;
533 $this->tokens[] = $token;
534 if (
is_array( $token ) && $token[0] === T_STRING ) {
548 foreach ( $this->tokens as $token ) {
553 $this->startToken =
null;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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.
string[] $psr4Namespaces
Configured PSR4 namespaces.
__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...
setPsr4Namespaces(array $namespaces)
Set PSR4 namespaces.
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
namespace and then decline to actually register it & $namespaces
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those classes
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
processing should stop and the error should be shown to the user * false
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(!is_readable( $file)) $ext