From: Kunal Mehta Date: Wed, 1 Apr 2015 20:42:21 +0000 (-0700) Subject: registration: Make it easier for other code to get extension metadata X-Git-Tag: 1.31.0-rc.0~11802^2~1 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=79e5e162575d2b321c7248d1023d165d9c5f81f4;p=lhc%2Fweb%2Fwiklou.git registration: Make it easier for other code to get extension metadata 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 --- diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index c06f7e396c..5ef3853484 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -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();