Galorefitz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/213468
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, 66 insertions(+), 39 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/68/213468/1
diff --git a/includes/utils/AutoloadGenerator.php
b/includes/utils/AutoloadGenerator.php
index 9cf8cab..6efa31e 100644
--- a/includes/utils/AutoloadGenerator.php
+++ b/includes/utils/AutoloadGenerator.php
@@ -126,58 +126,85 @@
* developers towards the appropriate way to update the autoload.
*/
public function generateAutoload( $commandName = 'AutoloadGenerator' ) {
- $content = array();
+ // We need to check whether an extenson.json exists or not, and
+ // incase it doesn't, update the autoload.php file.
- // 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(
+ if ( file_exists( $this->basepath . '/extension.json' ) ) {
+ $key = 'AutoloadClasses';
+ $json = json_decode( $this->basepath .
'/extension.json', true );
+
+ // 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 ) {
+ $json[$key][$fqcn] = $path;
+ }
+ }
+
+ foreach ( $this->overrides as $path => $fqcn ) {
+ $json[$key][$fqcn] = $path;
+ }
+
+ // Sorting the list of autoload classes.
+ ksort( $json );
+
+ // Update extension.json, using constants for the
required
+ // formatting.
+ file_put_contents( $this->basepath . '/extension.json',
json_encode( $json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
+ }
+
+ else {
+ // 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(
+ foreach ( $this->overrides as $fqcn => $path ) {
+ $content[$fqcn] = sprintf(
$format,
var_export( $fqcn, true ),
var_export( $path, true )
+ );
+ }
+
+ // sort for stable output
+ ksort( $content );
+
+ // 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
+ <?php
+ // This file is generated by $commandName, do not
adjust manually
+ // @codingStandardsIgnoreFile
+ global \${$this->variableName};
+
+ \${$this->variableName} {$op} array(
+ {$output}
+ );
+
+ EOD
);
}
- // sort for stable output
- ksort( $content );
-
- // 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
-<?php
-// This file is generated by $commandName, do not adjust manually
-// @codingStandardsIgnoreFile
-global \${$this->variableName};
-
-\${$this->variableName} {$op} array(
- {$output}
-);
-
-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: newchange
Gerrit-Change-Id: Idd601d7897634fae8c69f4d5338d9fc8f8b8f89b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Galorefitz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits