"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "includes/utils/AutoloadGenerator.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

AutoloadGenerator.php  (mediawiki-1.31.1):AutoloadGenerator.php  (mediawiki-1.32.0)
skipping to change at line 53 skipping to change at line 53
protected $overrides = []; protected $overrides = [];
/** /**
* Directories that should be excluded * Directories that should be excluded
* *
* @var string[] * @var string[]
*/ */
protected $excludePaths = []; protected $excludePaths = [];
/** /**
* Configured PSR4 namespaces
*
* @var string[] namespace => path
*/
protected $psr4Namespaces = [];
/**
* @param string $basepath Root path of the project being scanned for cla sses * @param string $basepath Root path of the project being scanned for cla sses
* @param array|string $flags * @param array|string $flags
* *
* local - If this flag is set $wgAutoloadLocalClasses will be build ins tead * local - If this flag is set $wgAutoloadLocalClasses will be build ins tead
* of $wgAutoloadClasses * of $wgAutoloadClasses
*/ */
public function __construct( $basepath, $flags = [] ) { public function __construct( $basepath, $flags = [] ) {
if ( !is_array( $flags ) ) { if ( !is_array( $flags ) ) {
$flags = [ $flags ]; $flags = [ $flags ];
} }
skipping to change at line 83 skipping to change at line 90
* @since 1.31 * @since 1.31
* @param string[] $paths * @param string[] $paths
*/ */
public function setExcludePaths( array $paths ) { public function setExcludePaths( array $paths ) {
foreach ( $paths as $path ) { foreach ( $paths as $path ) {
$this->excludePaths[] = self::normalizePathSeparator( $pa th ); $this->excludePaths[] = self::normalizePathSeparator( $pa th );
} }
} }
/** /**
* Set PSR4 namespaces
*
* Unlike self::setExcludePaths(), this will only skip outputting the
* autoloader entry when the namespace matches the path.
*
* @since 1.32
* @param string[] $namespaces Associative array mapping namespace to pat
h
*/
public function setPsr4Namespaces( array $namespaces ) {
foreach ( $namespaces as $ns => $path ) {
$ns = rtrim( $ns, '\\' ) . '\\';
$this->psr4Namespaces[$ns] = rtrim( self::normalizePathSe
parator( $path ), '/' );
}
}
/**
* Whether the file should be excluded * Whether the file should be excluded
* *
* @param string $path File path * @param string $path File path
* @return bool * @return bool
*/ */
private function shouldExclude( $path ) { private function shouldExclude( $path ) {
foreach ( $this->excludePaths as $dir ) { foreach ( $this->excludePaths as $dir ) {
if ( strpos( $path, $dir ) === 0 ) { if ( strpos( $path, $dir ) === 0 ) {
return true; return true;
} }
skipping to change at line 138 skipping to change at line 161
$len = strlen( $this->basepath ); $len = strlen( $this->basepath );
if ( substr( $inputPath, 0, $len ) !== $this->basepath ) { if ( substr( $inputPath, 0, $len ) !== $this->basepath ) {
throw new \Exception( "Path is not within basepath: $inpu tPath" ); throw new \Exception( "Path is not within basepath: $inpu tPath" );
} }
if ( $this->shouldExclude( $inputPath ) ) { if ( $this->shouldExclude( $inputPath ) ) {
return; return;
} }
$result = $this->collector->getClasses( $result = $this->collector->getClasses(
file_get_contents( $inputPath ) file_get_contents( $inputPath )
); );
// Filter out classes that will be found by PSR4
$result = array_filter( $result, function ( $class ) use ( $input
Path ) {
$parts = explode( '\\', $class );
for ( $i = count( $parts ) - 1; $i > 0; $i-- ) {
$ns = implode( '\\', array_slice( $parts, 0, $i )
) . '\\';
if ( isset( $this->psr4Namespaces[$ns] ) ) {
$expectedPath = $this->psr4Namespaces[$ns
] . '/'
. implode( '/', array_slice( $par
ts, $i ) )
. '.php';
if ( $inputPath === $expectedPath ) {
return false;
}
}
}
return true;
} );
if ( $result ) { if ( $result ) {
$shortpath = substr( $inputPath, $len ); $shortpath = substr( $inputPath, $len );
$this->classes[$shortpath] = $result; $this->classes[$shortpath] = $result;
} }
} }
/** /**
* @param string $dir Path to a directory to recursively search * @param string $dir Path to a directory to recursively search
* for php files with either .php or .inc extensions * for php files with either .php or .inc extensions
*/ */
skipping to change at line 261 skipping to change at line 303
/** /**
* Returns all known classes as a string, which can be used to put into a target * 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) * file (e.g. extension.json, skin.json or autoload.php)
* *
* @param string $commandName Value used in file comment to direct * @param string $commandName Value used in file comment to direct
* developers towards the appropriate way to update the autoload. * developers towards the appropriate way to update the autoload.
* @return string * @return string
*/ */
public function getAutoload( $commandName = 'AutoloadGenerator' ) { public function getAutoload( $commandName = 'AutoloadGenerator' ) {
// We need to check whether an extenson.json or skin.json exists or not, and // We need to check whether an extension.json or skin.json exists or not, and
// incase it doesn't, update the autoload.php file. // incase it doesn't, update the autoload.php file.
$fileinfo = $this->getTargetFileinfo(); $fileinfo = $this->getTargetFileinfo();
if ( $fileinfo['type'] === self::FILETYPE_JSON ) { if ( $fileinfo['type'] === self::FILETYPE_JSON ) {
return $this->generateJsonAutoload( $fileinfo['filename'] ); return $this->generateJsonAutoload( $fileinfo['filename'] );
} else { } else {
return $this->generatePHPAutoload( $commandName, $fileinf o['filename'] ); return $this->generatePHPAutoload( $commandName, $fileinf o['filename'] );
} }
} }
skipping to change at line 392 skipping to change at line 434
/** /**
* Determine if $token begins the next expect sequence. * Determine if $token begins the next expect sequence.
* *
* @param array $token * @param array $token
*/ */
protected function tryBeginExpect( $token ) { protected function tryBeginExpect( $token ) {
if ( is_string( $token ) ) { if ( is_string( $token ) ) {
return; return;
} }
// Note: When changing class name discovery logic, // Note: When changing class name discovery logic,
// AutoLoaderTest.php may also need to be updated. // AutoLoaderStructureTest.php may also need to be updated.
switch ( $token[0] ) { switch ( $token[0] ) {
case T_NAMESPACE: case T_NAMESPACE:
case T_CLASS: case T_CLASS:
case T_INTERFACE: case T_INTERFACE:
case T_TRAIT: case T_TRAIT:
case T_DOUBLE_COLON: case T_DOUBLE_COLON:
case T_NEW:
$this->startToken = $token; $this->startToken = $token;
break; break;
case T_STRING: case T_STRING:
if ( $token[1] === 'class_alias' ) { if ( $token[1] === 'class_alias' ) {
$this->startToken = $token; $this->startToken = $token;
$this->alias = []; $this->alias = [];
} }
} }
} }
skipping to change at line 421 skipping to change at line 464
* *
* @param array $token * @param array $token
*/ */
protected function tryEndExpect( $token ) { protected function tryEndExpect( $token ) {
switch ( $this->startToken[0] ) { switch ( $this->startToken[0] ) {
case T_DOUBLE_COLON: case T_DOUBLE_COLON:
// Skip over T_CLASS after T_DOUBLE_COLON because this is something like // Skip over T_CLASS after T_DOUBLE_COLON because this is something like
// "self::static" which accesses the class name. It doens't define a new class. // "self::static" which accesses the class name. It doens't define a new class.
$this->startToken = null; $this->startToken = null;
break; break;
case T_NEW:
// Skip over T_CLASS after T_NEW because this is
a PHP 7 anonymous class.
if ( !is_array( $token ) || $token[0] !== T_WHITE
SPACE ) {
$this->startToken = null;
}
break;
case T_NAMESPACE: case T_NAMESPACE:
if ( $token === ';' || $token === '{' ) { if ( $token === ';' || $token === '{' ) {
$this->namespace = $this->implodeTokens() . '\\'; $this->namespace = $this->implodeTokens() . '\\';
} else { } else {
$this->tokens[] = $token; $this->tokens[] = $token;
} }
break; break;
case T_STRING: case T_STRING:
if ( $this->alias !== null ) { if ( $this->alias !== null ) {
 End of changes. 7 change blocks. 
2 lines changed or deleted 59 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)