Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / includes / registration / ExtensionRegistry.php
index fb89731..9cae73c 100644 (file)
@@ -86,6 +86,13 @@ class ExtensionRegistry {
         */
        protected $testAttributes = [];
 
+       /**
+        * Whether to check dev-requires
+        *
+        * @var bool
+        */
+       protected $checkDev = false;
+
        /**
         * @var ExtensionRegistry
         */
@@ -103,6 +110,14 @@ class ExtensionRegistry {
                return self::$instance;
        }
 
+       /**
+        * @since 1.34
+        * @param bool $check
+        */
+       public function setCheckDevRequires( $check ) {
+               $this->checkDev = $check;
+       }
+
        /**
         * @param string $path Absolute path to the JSON file
         */
@@ -148,6 +163,7 @@ class ExtensionRegistry {
                        'registration' => self::CACHE_VERSION,
                        'mediawiki' => $wgVersion,
                        'abilities' => $this->getAbilities(),
+                       'checkDev' => $this->checkDev,
                ];
 
                // We use a try/catch because we don't want to fail here
@@ -284,6 +300,13 @@ class ExtensionRegistry {
                        }
 
                        $dir = dirname( $path );
+                       self::exportAutoloadClassesAndNamespaces(
+                               $dir,
+                               $info,
+                               $autoloadClasses,
+                               $autoloadNamespaces
+                       );
+
                        if ( isset( $info['AutoloadClasses'] ) ) {
                                $autoload = $this->processAutoLoader( $dir, $info['AutoloadClasses'] );
                                $GLOBALS['wgAutoloadClasses'] += $autoload;
@@ -295,7 +318,7 @@ class ExtensionRegistry {
                        }
 
                        // get all requirements/dependencies for this extension
-                       $requires = $processor->getRequirements( $info );
+                       $requires = $processor->getRequirements( $info, $this->checkDev );
 
                        // validate the information needed and add the requirements
                        if ( is_array( $requires ) && $requires && isset( $info['name'] ) ) {
@@ -331,6 +354,28 @@ class ExtensionRegistry {
                return $data;
        }
 
+       /**
+        * Export autoload classes and namespaces for a given directory and parsed JSON info file.
+        *
+        * @param string $dir
+        * @param array $info
+        * @param array &$autoloadClasses
+        * @param array &$autoloadNamespaces
+        */
+       public static function exportAutoloadClassesAndNamespaces(
+               $dir, $info, &$autoloadClasses = [], &$autoloadNamespaces = []
+       ) {
+               if ( isset( $info['AutoloadClasses'] ) ) {
+                       $autoload = self::processAutoLoader( $dir, $info['AutoloadClasses'] );
+                       $GLOBALS['wgAutoloadClasses'] += $autoload;
+                       $autoloadClasses += $autoload;
+               }
+               if ( isset( $info['AutoloadNamespaces'] ) ) {
+                       $autoloadNamespaces += self::processAutoLoader( $dir, $info['AutoloadNamespaces'] );
+                       AutoLoader::$psr4Namespaces += $autoloadNamespaces;
+               }
+       }
+
        protected function exportExtractedData( array $info ) {
                foreach ( $info['globals'] as $key => $val ) {
                        // If a merge strategy is set, read it and remove it from the value
@@ -495,7 +540,7 @@ class ExtensionRegistry {
         * @param array $files
         * @return array
         */
-       protected function processAutoLoader( $dir, array $files ) {
+       protected static function processAutoLoader( $dir, array $files ) {
                // Make paths absolute, relative to the JSON file
                foreach ( $files as &$file ) {
                        $file = "$dir/$file";