jenkins-bot has submitted this change and it was merged.

Change subject: AutoloadGenerator.php: Update 'AutoloadClasses' in 
extension.json
......................................................................


AutoloadGenerator.php: Update 'AutoloadClasses' in extension.json

AutoloadGenerator.php until now only updated autoload.php. As we shift
to extension registration, it would be cleaner if AutoloadGenerator.php
directly updates 'AutoloadClasses' in extension.json.

Bug: T88194
Change-Id: Idd601d7897634fae8c69f4d5338d9fc8f8b8f89b
---
M includes/utils/AutoloadGenerator.php
1 file changed, 65 insertions(+), 32 deletions(-)

Approvals:
  Mattflaschen: Looks good to me, approved
  Polybuildr: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/includes/utils/AutoloadGenerator.php 
b/includes/utils/AutoloadGenerator.php
index 9cf8cab..dd1a38a 100644
--- a/includes/utils/AutoloadGenerator.php
+++ b/includes/utils/AutoloadGenerator.php
@@ -126,45 +126,78 @@
         *  developers towards the appropriate way to update the autoload.
         */
        public function generateAutoload( $commandName = 'AutoloadGenerator' ) {
-               $content = array();
 
-               // We need to generate a line each rather than exporting the
-               // full array so __DIR__ can be prepended to all the paths
-               $format = "%s => __DIR__ . %s,";
-               foreach ( $this->classes as $path => $contained ) {
-                       $exportedPath = var_export( $path, true );
-                       foreach ( $contained as $fqcn ) {
+               // We need to check whether an extenson.json exists or not, and
+               // incase it doesn't, update the autoload.php file.
+
+               if ( file_exists( $this->basepath . '/extension.json' ) ) {
+                       require_once __DIR__ . 
'/../../includes/json/FormatJson.php';
+                       $key = 'AutoloadClasses';
+                       $json = FormatJson::decode( file_get_contents( 
$this->basepath
+                               . '/extension.json' ), true );
+                       unset( $json[$key] );
+                       // Inverting the key-value pairs so that they become of 
the
+                       // format class-name : path when they get converted 
into json.
+                       foreach ( $this->classes as $path => $contained ) {
+                               foreach ( $contained as $fqcn ) {
+
+                                       // Using substr to remove the leading 
'/'
+                                       $json[$key][$fqcn] = substr( $path, 1 );
+                               }
+                       }
+                       foreach ( $this->overrides as $path => $fqcn ) {
+
+                               // Using substr to remove the leading '/'
+                               $json[$key][$fqcn] = substr( $path, 1 );
+                       }
+
+                       // Sorting the list of autoload classes.
+                       ksort( $json[$key] );
+
+                       // Update extension.json, using constants for the 
required
+                       // formatting.
+                       file_put_contents( $this->basepath . '/extension.json',
+                               FormatJson::encode( $json, true ) . "\n" );
+               } else {
+                       $content = array();
+
+                       // We need to generate a line each rather than 
exporting the
+                       // full array so __DIR__ can be prepended to all the 
paths
+                       $format = "%s => __DIR__ . %s,";
+                       foreach ( $this->classes as $path => $contained ) {
+                               $exportedPath = var_export( $path, true );
+                               foreach ( $contained as $fqcn ) {
+                                       $content[$fqcn] = sprintf(
+                                               $format,
+                                               var_export( $fqcn, true ),
+                                               $exportedPath
+                                       );
+                               }
+                       }
+
+                       foreach ( $this->overrides as $fqcn => $path ) {
                                $content[$fqcn] = sprintf(
                                        $format,
                                        var_export( $fqcn, true ),
-                                       $exportedPath
+                                       var_export( $path, true )
                                );
                        }
-               }
 
-               foreach ( $this->overrides as $fqcn => $path ) {
-                       $content[$fqcn] = sprintf(
-                               $format,
-                               var_export( $fqcn, true ),
-                               var_export( $path, true )
-                       );
-               }
+                       // sort for stable output
+                       ksort( $content );
 
-               // sort for stable output
-               ksort( $content );
+                       // extensions using this generator are appending to the 
existing
+                       // autoload.
+                       if ( $this->variableName === 'wgAutoloadClasses' ) {
+                               $op = '+=';
+                       } else {
+                               $op = '=';
+                       }
 
-               // extensions using this generator are appending to the existing
-               // autoload.
-               if ( $this->variableName === 'wgAutoloadClasses' ) {
-                       $op = '+=';
-               } else {
-                       $op = '=';
-               }
-
-               $output = implode( "\n\t", $content );
-               file_put_contents(
-                       $this->basepath . '/autoload.php',
-                       <<<EOD
+                       $output = implode( "\n\t", $content );
+                       file_put_contents(
+                               $this->basepath . '/autoload.php',
+                               <<<EOD
 <?php
 // This file is generated by $commandName, do not adjust manually
 // @codingStandardsIgnoreFile
@@ -175,9 +208,9 @@
 );
 
 EOD
-               );
+                       );
+               }
        }
-
        /**
         * Ensure that Unix-style path separators ("/") are used in the path.
         *

-- 
To view, visit https://gerrit.wikimedia.org/r/213468
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Idd601d7897634fae8c69f4d5338d9fc8f8b8f89b
Gerrit-PatchSet: 14
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Galorefitz <smritis.31...@gmail.com>
Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.wel...@t-online.de>
Gerrit-Reviewer: Galorefitz <smritis.31...@gmail.com>
Gerrit-Reviewer: Kaldari <rkald...@wikimedia.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Mattflaschen <mflasc...@wikimedia.org>
Gerrit-Reviewer: Paladox <thomasmulhall...@yahoo.com>
Gerrit-Reviewer: Polybuildr <v.a.ghai...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to