Add tests for ExtensionJsonValidator
[lhc/web/wiklou.git] / includes / registration / ExtensionProcessor.php
index ffc7a7e..0d0a6e4 100644 (file)
@@ -197,8 +197,20 @@ class ExtensionProcessor implements Processor {
                $this->extractMessagesDirs( $dir, $info );
                $this->extractNamespaces( $info );
                $this->extractResourceLoaderModules( $dir, $info );
-               $this->extractServiceWiringFiles( $dir, $info );
-               $this->extractParserTestFiles( $dir, $info );
+               if ( isset( $info['ServiceWiringFiles'] ) ) {
+                       $this->extractPathBasedGlobal(
+                               'wgServiceWiringFiles',
+                               $dir,
+                               $info['ServiceWiringFiles']
+                       );
+               }
+               if ( isset( $info['ParserTestFiles'] ) ) {
+                       $this->extractPathBasedGlobal(
+                               'wgParserTestFiles',
+                               $dir,
+                               $info['ParserTestFiles']
+                       );
+               }
                $name = $this->extractCredits( $path, $info );
                if ( isset( $info['callback'] ) ) {
                        $this->callbacks[$name] = $info['callback'];
@@ -378,9 +390,10 @@ class ExtensionProcessor implements Processor {
 
        protected function extractExtensionMessagesFiles( $dir, array $info ) {
                if ( isset( $info['ExtensionMessagesFiles'] ) ) {
-                       $this->globals["wgExtensionMessagesFiles"] += array_map( function ( $file ) use ( $dir ) {
-                               return "$dir/$file";
-                       }, $info['ExtensionMessagesFiles'] );
+                       foreach ( $info['ExtensionMessagesFiles'] as &$file ) {
+                               $file = "$dir/$file";
+                       }
+                       $this->globals["wgExtensionMessagesFiles"] += $info['ExtensionMessagesFiles'];
                }
        }
 
@@ -450,7 +463,7 @@ class ExtensionProcessor implements Processor {
                        }
                        foreach ( $info['config'] as $key => $val ) {
                                if ( $key[0] !== '@' ) {
-                                       $this->globals["$prefix$key"] = $val;
+                                       $this->addConfigGlobal( "$prefix$key", $val );
                                }
                        }
                }
@@ -478,24 +491,29 @@ class ExtensionProcessor implements Processor {
                                if ( isset( $data['path'] ) && $data['path'] ) {
                                        $value = "$dir/$value";
                                }
-                               $this->globals["$prefix$key"] = $value;
+                               $this->addConfigGlobal( "$prefix$key", $value );
                        }
                }
        }
 
-       protected function extractServiceWiringFiles( $dir, array $info ) {
-               if ( isset( $info['ServiceWiringFiles'] ) ) {
-                       foreach ( $info['ServiceWiringFiles'] as $path ) {
-                               $this->globals['wgServiceWiringFiles'][] = "$dir/$path";
-                       }
+       /**
+        * Helper function to set a value to a specific global, if it isn't set already.
+        *
+        * @param string $key The config key with the prefix and anything
+        * @param mixed $value The value of the config
+        */
+       private function addConfigGlobal( $key, $value ) {
+               if ( array_key_exists( $key, $this->globals ) ) {
+                       throw new RuntimeException(
+                               "The configuration setting '$key' was already set by another extension,"
+                               . " and cannot be set again." );
                }
+               $this->globals[$key] = $value;
        }
 
-       protected function extractParserTestFiles( $dir, array $info ) {
-               if ( isset( $info['ParserTestFiles'] ) ) {
-                       foreach ( $info['ParserTestFiles'] as $path ) {
-                               $this->globals['wgParserTestFiles'][] = "$dir/$path";
-                       }
+       protected function extractPathBasedGlobal( $global, $dir, $paths ) {
+               foreach ( $paths as $path ) {
+                       $this->globals[$global][] = "$dir/$path";
                }
        }