registration: Make it easier for other code to get extension metadata
authorKunal Mehta <legoktm@gmail.com>
Wed, 1 Apr 2015 20:42:21 +0000 (13:42 -0700)
committerKunal Mehta <legoktm@gmail.com>
Wed, 1 Apr 2015 20:42:21 +0000 (13:42 -0700)
Right now if other code wanted to access extension metadata from
extension.json, it would have to either re-implement parts of
loadFromQueue() or make assumptions about the processor and schema being
used.

Lets split that code out in to a public readFromQueue() function that
returns all extracted data from the processors.

Change-Id: I314d73341d3faaa47e01f722123c20fd8f61da8a

includes/registration/ExtensionRegistry.php

index c06f7e3..5ef3853 100644 (file)
@@ -91,41 +91,55 @@ class ExtensionRegistry {
                if ( $data ) {
                        $this->exportExtractedData( $data );
                } else {
-                       $data = array( 'globals' => array( 'wgAutoloadClasses' => array() ) );
-                       $autoloadClasses = array();
-                       foreach ( $this->queued as $path => $mtime ) {
-                               $json = file_get_contents( $path );
-                               $info = json_decode( $json, /* $assoc = */ true );
-                               if ( !is_array( $info ) ) {
-                                       throw new Exception( "$path is not a valid JSON file." );
-                               }
-                               $autoload = $this->processAutoLoader( dirname( $path ), $info );
-                               // Set up the autoloader now so custom processors will work
-                               $GLOBALS['wgAutoloadClasses'] += $autoload;
-                               $autoloadClasses += $autoload;
-                               if ( isset( $info['processor'] ) ) {
-                                       $processor = $this->getProcessor( $info['processor'] );
-                               } else {
-                                       $processor = $this->getProcessor( 'default' );
-                               }
-                               $processor->extractInfo( $path, $info );
-                       }
-                       foreach ( $this->processors as $processor ) {
-                               $data = array_merge_recursive( $data, $processor->getExtractedInfo() );
-                       }
-                       foreach ( $data['credits'] as $credit ) {
-                               $data['globals']['wgExtensionCredits'][$credit['type']][] = $credit;
-                       }
-                       $this->processors = array(); // Reset
+                       $data = $this->readFromQueue( $this->queued );
                        $this->exportExtractedData( $data );
                        // Do this late since we don't want to extract it since we already
                        // did that, but it should be cached
-                       $data['globals']['wgAutoloadClasses'] += $autoloadClasses;
+                       $data['globals']['wgAutoloadClasses'] += $data['autoload'];
+                       unset( $data['autoload'] );
                        $this->cache->set( $key, $data );
                }
                $this->queued = array();
        }
 
+       /**
+        * Process a queue of extensions and return their extracted data
+        *
+        * @param array $queue keys are filenames, values are ignored
+        * @return array extracted info
+        * @throws Exception
+        */
+       public function readFromQueue( array $queue ) {
+               $data = array( 'globals' => array( 'wgAutoloadClasses' => array() ) );
+               $autoloadClasses = array();
+               foreach ( $queue as $path => $mtime ) {
+                       $json = file_get_contents( $path );
+                       $info = json_decode( $json, /* $assoc = */ true );
+                       if ( !is_array( $info ) ) {
+                               throw new Exception( "$path is not a valid JSON file." );
+                       }
+                       $autoload = $this->processAutoLoader( dirname( $path ), $info );
+                       // Set up the autoloader now so custom processors will work
+                       $GLOBALS['wgAutoloadClasses'] += $autoload;
+                       $autoloadClasses += $autoload;
+                       if ( isset( $info['processor'] ) ) {
+                               $processor = $this->getProcessor( $info['processor'] );
+                       } else {
+                               $processor = $this->getProcessor( 'default' );
+                       }
+                       $processor->extractInfo( $path, $info );
+               }
+               foreach ( $this->processors as $processor ) {
+                       $data = array_merge_recursive( $data, $processor->getExtractedInfo() );
+               }
+               foreach ( $data['credits'] as $credit ) {
+                       $data['globals']['wgExtensionCredits'][$credit['type']][] = $credit;
+               }
+               $this->processors = array(); // Reset
+               $data['autoload'] = $autoloadClasses;
+               return $data;
+       }
+
        protected function getProcessor( $type ) {
                if ( !isset( $this->processors[$type] ) ) {
                        $processor = $type === 'default' ? new ExtensionProcessor() : new $type();