X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Futils%2FAutoloadGenerator.php;h=54a86775f8b020194e00b3f52d6688e70a4dbe03;hb=853b17ef5788be25045855ab340c9e0d8b443218;hp=0bfd4a27fa13318e0e6f764fb4f2a9e5b72fabf8;hpb=21f2b1e099c12e44083c3a6de0abd6561964ea6d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/utils/AutoloadGenerator.php b/includes/utils/AutoloadGenerator.php index 0bfd4a27fa..54a86775f8 100644 --- a/includes/utils/AutoloadGenerator.php +++ b/includes/utils/AutoloadGenerator.php @@ -152,7 +152,7 @@ class AutoloadGenerator { ksort( $json[$key] ); // Return the whole JSON file - return FormatJson::encode( $json, true ) . "\n"; + return FormatJson::encode( $json, "\t", FormatJson::ALL_OK ) . "\n"; } /** @@ -212,7 +212,6 @@ global \${$this->variableName}; ]; EOD; - } /** @@ -291,15 +290,6 @@ EOD; foreach ( glob( $this->basepath . '/*.php' ) as $file ) { $this->readFile( $file ); } - - // Legacy aliases (1.28) - $this->forceClassPath( 'DatabaseBase', - $this->basepath . '/includes/libs/rdbms/database/Database.php' ); - // Legacy aliases (1.29) - $this->forceClassPath( 'Blob', - $this->basepath . '/includes/libs/rdbms/encasing/Blob.php' ); - $this->forceClassPath( 'Field', - $this->basepath . '/includes/libs/rdbms/field/Field.php' ); } } @@ -328,6 +318,11 @@ class ClassCollector { */ protected $tokens; + /** + * @var array Class alias with target/name fields + */ + protected $alias; + /** * @var string $code PHP code (including namespace = ''; $this->classes = []; $this->startToken = null; + $this->alias = null; $this->tokens = []; foreach ( token_get_all( $code ) as $token ) { @@ -358,6 +354,8 @@ class ClassCollector { if ( is_string( $token ) ) { return; } + // Note: When changing class name discovery logic, + // AutoLoaderTest.php may also need to be updated. switch ( $token[0] ) { case T_NAMESPACE: case T_CLASS: @@ -365,6 +363,12 @@ class ClassCollector { case T_TRAIT: case T_DOUBLE_COLON: $this->startToken = $token; + break; + case T_STRING: + if ( $token[1] === 'class_alias' ) { + $this->startToken = $token; + $this->alias = []; + } } } @@ -388,6 +392,58 @@ class ClassCollector { } break; + case T_STRING: + if ( $this->alias !== null ) { + // Flow 1 - Two string literals: + // - T_STRING class_alias + // - '(' + // - T_CONSTANT_ENCAPSED_STRING 'TargetClass' + // - ',' + // - T_WHITESPACE + // - T_CONSTANT_ENCAPSED_STRING 'AliasName' + // - ')' + // Flow 2 - Use of ::class syntax for first parameter + // - T_STRING class_alias + // - '(' + // - T_STRING TargetClass + // - T_DOUBLE_COLON :: + // - T_CLASS class + // - ',' + // - T_WHITESPACE + // - T_CONSTANT_ENCAPSED_STRING 'AliasName' + // - ')' + if ( $token === '(' ) { + // Start of a function call to class_alias() + $this->alias = [ 'target' => false, 'name' => false ]; + } elseif ( $token === ',' ) { + // Record that we're past the first parameter + if ( $this->alias['target'] === false ) { + $this->alias['target'] = true; + } + } elseif ( is_array( $token ) && $token[0] === T_CONSTANT_ENCAPSED_STRING ) { + if ( $this->alias['target'] === true ) { + // We already saw a first argument, this must be the second. + // Strip quotes from the string literal. + $this->alias['name'] = substr( $token[1], 1, -1 ); + } + } elseif ( $token === ')' ) { + // End of function call + $this->classes[] = $this->alias['name']; + $this->alias = null; + $this->startToken = null; + } elseif ( !is_array( $token ) || ( + $token[0] !== T_STRING && + $token[0] !== T_DOUBLE_COLON && + $token[0] !== T_CLASS && + $token[0] !== T_WHITESPACE + ) ) { + // Ignore this call to class_alias() - compat/Timestamp.php + $this->alias = null; + $this->startToken = null; + } + } + break; + case T_CLASS: case T_INTERFACE: case T_TRAIT: