Revert "Split ClassCollector class into own file"
authorPleaseStand <pleasestand@live.com>
Mon, 4 Apr 2016 03:26:24 +0000 (03:26 +0000)
committerPleaseStand <pleasestand@live.com>
Mon, 4 Apr 2016 03:26:24 +0000 (03:26 +0000)
The AutoloadGenerator class is instantiated in the script
maintenance/generateLocalAutoload.php and its equivalents in
several extensions, none of which use MediaWiki's AutoLoader,
so you get a "Fatal error: Class 'ClassCollector' not found".

This reverts commit a379bebd03099ee056a5ae7466f0699423064ede.

Change-Id: Ia6a7a1cb8a593ac86ecffdb690064e0b8ad68b47

autoload.php
includes/utils/AutoloadGenerator.php
includes/utils/ClassCollector.php [deleted file]

index 67a235f..fd4f873 100644 (file)
@@ -230,7 +230,7 @@ $wgAutoloadLocalClasses = [
        'CheckSyntax' => __DIR__ . '/maintenance/checkSyntax.php',
        'CheckUsernames' => __DIR__ . '/maintenance/checkUsernames.php',
        'ChronologyProtector' => __DIR__ . '/includes/db/ChronologyProtector.php',
-       'ClassCollector' => __DIR__ . '/includes/utils/ClassCollector.php',
+       'ClassCollector' => __DIR__ . '/includes/utils/AutoloadGenerator.php',
        'CleanupAncientTables' => __DIR__ . '/maintenance/cleanupAncientTables.php',
        'CleanupBlocks' => __DIR__ . '/maintenance/cleanupBlocks.php',
        'CleanupPreferences' => __DIR__ . '/maintenance/cleanupPreferences.php',
index 4101879..916e2f8 100644 (file)
@@ -250,3 +250,117 @@ EOD
                return str_replace( '\\', '/', $path );
        }
 }
+
+/**
+ * Reads PHP code and returns the FQCN of every class defined within it.
+ */
+class ClassCollector {
+
+       /**
+        * @var string Current namespace
+        */
+       protected $namespace = '';
+
+       /**
+        * @var array List of FQCN detected in this pass
+        */
+       protected $classes;
+
+       /**
+        * @var array Token from token_get_all() that started an expect sequence
+        */
+       protected $startToken;
+
+       /**
+        * @var array List of tokens that are members of the current expect sequence
+        */
+       protected $tokens;
+
+       /**
+        * @var string $code PHP code (including <?php) to detect class names from
+        * @return array List of FQCN detected within the tokens
+        */
+       public function getClasses( $code ) {
+               $this->namespace = '';
+               $this->classes = [];
+               $this->startToken = null;
+               $this->tokens = [];
+
+               foreach ( token_get_all( $code ) as $token ) {
+                       if ( $this->startToken === null ) {
+                               $this->tryBeginExpect( $token );
+                       } else {
+                               $this->tryEndExpect( $token );
+                       }
+               }
+
+               return $this->classes;
+       }
+
+       /**
+        * Determine if $token begins the next expect sequence.
+        *
+        * @param array $token
+        */
+       protected function tryBeginExpect( $token ) {
+               if ( is_string( $token ) ) {
+                       return;
+               }
+               switch ( $token[0] ) {
+               case T_NAMESPACE:
+               case T_CLASS:
+               case T_INTERFACE:
+               case T_TRAIT:
+               case T_DOUBLE_COLON:
+                       $this->startToken = $token;
+               }
+       }
+
+       /**
+        * Accepts the next token in an expect sequence
+        *
+        * @param array
+        */
+       protected function tryEndExpect( $token ) {
+               switch ( $this->startToken[0] ) {
+               case T_DOUBLE_COLON:
+                       // 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.
+                       $this->startToken = null;
+                       break;
+               case T_NAMESPACE:
+                       if ( $token === ';' || $token === '{' ) {
+                               $this->namespace = $this->implodeTokens() . '\\';
+                       } else {
+                               $this->tokens[] = $token;
+                       }
+                       break;
+
+               case T_CLASS:
+               case T_INTERFACE:
+               case T_TRAIT:
+                       $this->tokens[] = $token;
+                       if ( is_array( $token ) && $token[0] === T_STRING ) {
+                               $this->classes[] = $this->namespace . $this->implodeTokens();
+                       }
+               }
+       }
+
+       /**
+        * Returns the string representation of the tokens within the
+        * current expect sequence and resets the sequence.
+        *
+        * @return string
+        */
+       protected function implodeTokens() {
+               $content = [];
+               foreach ( $this->tokens as $token ) {
+                       $content[] = is_string( $token ) ? $token : $token[1];
+               }
+
+               $this->tokens = [];
+               $this->startToken = null;
+
+               return trim( implode( '', $content ), " \n\t" );
+       }
+}
diff --git a/includes/utils/ClassCollector.php b/includes/utils/ClassCollector.php
deleted file mode 100644 (file)
index 25231df..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-
-/**
- * Reads PHP code and returns the FQCN of every class defined within it.
- */
-class ClassCollector {
-
-       /**
-        * @var string Current namespace
-        */
-       protected $namespace = '';
-
-       /**
-        * @var array List of FQCN detected in this pass
-        */
-       protected $classes;
-
-       /**
-        * @var array Token from token_get_all() that started an expect sequence
-        */
-       protected $startToken;
-
-       /**
-        * @var array List of tokens that are members of the current expect sequence
-        */
-       protected $tokens;
-
-       /**
-        * @var string $code PHP code (including <?php) to detect class names from
-        * @return array List of FQCN detected within the tokens
-        */
-       public function getClasses( $code ) {
-               $this->namespace = '';
-               $this->classes = [];
-               $this->startToken = null;
-               $this->tokens = [];
-
-               foreach ( token_get_all( $code ) as $token ) {
-                       if ( $this->startToken === null ) {
-                               $this->tryBeginExpect( $token );
-                       } else {
-                               $this->tryEndExpect( $token );
-                       }
-               }
-
-               return $this->classes;
-       }
-
-       /**
-        * Determine if $token begins the next expect sequence.
-        *
-        * @param array $token
-        */
-       protected function tryBeginExpect( $token ) {
-               if ( is_string( $token ) ) {
-                       return;
-               }
-               switch ( $token[0] ) {
-                       case T_NAMESPACE:
-                       case T_CLASS:
-                       case T_INTERFACE:
-                       case T_TRAIT:
-                       case T_DOUBLE_COLON:
-                               $this->startToken = $token;
-               }
-       }
-
-       /**
-        * Accepts the next token in an expect sequence
-        *
-        * @param array
-        */
-       protected function tryEndExpect( $token ) {
-               switch ( $this->startToken[0] ) {
-                       case T_DOUBLE_COLON:
-                               // 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.
-                               $this->startToken = null;
-                               break;
-                       case T_NAMESPACE:
-                               if ( $token === ';' || $token === '{' ) {
-                                       $this->namespace = $this->implodeTokens() . '\\';
-                               } else {
-                                       $this->tokens[] = $token;
-                               }
-                               break;
-
-                       case T_CLASS:
-                       case T_INTERFACE:
-                       case T_TRAIT:
-                               $this->tokens[] = $token;
-                               if ( is_array( $token ) && $token[0] === T_STRING ) {
-                                       $this->classes[] = $this->namespace . $this->implodeTokens();
-                               }
-               }
-       }
-
-       /**
-        * Returns the string representation of the tokens within the
-        * current expect sequence and resets the sequence.
-        *
-        * @return string
-        */
-       protected function implodeTokens() {
-               $content = [];
-               foreach ( $this->tokens as $token ) {
-                       $content[] = is_string( $token ) ? $token : $token[1];
-               }
-
-               $this->tokens = [];
-               $this->startToken = null;
-
-               return trim( implode( '', $content ), " \n\t" );
-       }
-}