Skip to content

Commit ccafa91

Browse files
Merge branch 'MC-5465-static-refactor' into MC-5465
2 parents 58ae308 + 8648dc5 commit ccafa91

File tree

18 files changed

+358
-205
lines changed

18 files changed

+358
-205
lines changed

src/Magento/ComposerRootUpdatePlugin/ComposerReimplementation/ExtendableRequireCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ abstract class ExtendableRequireCommand extends RequireCommand
4040
protected $mageNewlyCreated;
4141

4242
/**
43-
* @var bool|string $mageComposerBackup
43+
* @var boolean|string $mageComposerBackup
4444
*/
4545
protected $mageComposerBackup;
4646

src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/MageRootRequireCommand.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ class MageRootRequireCommand extends ExtendableRequireCommand
4040
/**
4141
* @var RootPackageRetriever $retriever
4242
*/
43-
private $retriever;
43+
protected $retriever;
44+
45+
/**
46+
* @var Console $console
47+
*/
48+
protected $console;
4449

4550
/**
4651
* Call the parent setApplication method but also change the command's name to update
@@ -55,7 +60,6 @@ public function setApplication(Application $application = null)
5560
// added to the command registry
5661
$this->setName($this->commandName);
5762
parent::setApplication($application);
58-
Console::setIO($this->getIO());
5963
}
6064

6165
/**
@@ -136,7 +140,7 @@ public function configure()
136140
public function execute(InputInterface $input, OutputInterface $output)
137141
{
138142
$updater = null;
139-
Console::setIO($this->getIO());
143+
$this->console = new Console($this->getIO(), $input->getOption(static::INTERACTIVE_OPT));
140144
$fileParsed = $this->parseComposerJsonFile($input);
141145
if ($fileParsed !== 0) {
142146
return $fileParsed;
@@ -167,12 +171,12 @@ public function execute(InputInterface $input, OutputInterface $output)
167171

168172
// Found a Magento product in the command arguments; try to run the updater
169173
try {
170-
$updater = new MagentoRootUpdater($this->getComposer());
174+
$updater = new MagentoRootUpdater($this->console, $this->getComposer());
171175
$didUpdate = $this->runUpdate($updater, $input, $edition, $constraint);
172176
} catch (\Exception $e) {
173177
$label = 'Magento ' . ucfirst($edition) . " Edition $constraint";
174178
$this->revertMageComposerFile("Update of composer.json with $label changes failed");
175-
Console::log($e->getMessage());
179+
$this->console->log($e->getMessage());
176180
$didUpdate = false;
177181
}
178182

@@ -183,12 +187,12 @@ public function execute(InputInterface $input, OutputInterface $output)
183187
if ($didUpdate) {
184188
// Update composer.json before the native execute(), as it reads the file instead of an in-memory object
185189
$label = $this->retriever->getTargetLabel();
186-
Console::info("Updating composer.json for $label ...");
190+
$this->console->info("Updating composer.json for $label ...");
187191
try {
188192
$updater->writeUpdatedComposerJson();
189193
} catch (\Exception $e) {
190194
$this->revertMageComposerFile("Update of composer.json with $label changes failed");
191-
Console::log($e->getMessage());
195+
$this->console->log($e->getMessage());
192196
$didUpdate = false;
193197
}
194198
}
@@ -207,7 +211,7 @@ public function execute(InputInterface $input, OutputInterface $output)
207211
// If the native execute() didn't succeed, revert the Magento changes to the composer.json file
208212
$this->revertMageComposerFile('The native \'composer ' . $this->commandName . '\' command failed');
209213
if ($constraint && !PackageUtils::isConstraintStrict($constraint)) {
210-
Console::comment(
214+
$this->console->comment(
211215
"Recommended: Use a specific Magento version constraint instead of \"$package: $constraint\""
212216
);
213217
}
@@ -243,8 +247,8 @@ protected function runUpdate($updater, $input, $targetEdition, $targetConstraint
243247
}
244248
}
245249

246-
Console::setInteractive($input->getOption(static::INTERACTIVE_OPT));
247250
$this->retriever = new RootPackageRetriever(
251+
$this->console,
248252
$this->getComposer(),
249253
$targetEdition,
250254
$targetConstraint,

src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/UpdatePluginNamespaceCommands.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ class UpdatePluginNamespaceCommands extends BaseCommand
2222
{
2323
const NAME = 'magento-update-plugin';
2424

25+
/**
26+
* @var Console $console
27+
*/
28+
protected $console;
29+
2530
/**
2631
* Map of operation command to description
2732
*
2833
* @var array $operations
2934
*/
30-
private static $operations = [
35+
protected static $operations = [
3136
'list' =>
3237
"List all operations available in the <comment>%command.name%</comment> namespace. This is equivalent\n".
3338
'to running <comment>%command.full_name%</comment> without an operation.',
@@ -61,16 +66,17 @@ protected function configure()
6166
*/
6267
protected function execute(InputInterface $input, OutputInterface $output)
6368
{
69+
$this->console = new Console($this->getIO());
6470
$operation = $input->getArgument('operation');
65-
Console::setIO($this->getIO());
6671
if (empty($operation) || $operation == 'list') {
67-
Console::log(static::describeOperations() . "\n");
72+
$this->console->log(static::describeOperations() . "\n");
6873
return 0;
6974
}
7075
if ($operation == 'install') {
71-
return WebSetupWizardPluginInstaller::doVarInstall();
76+
$setupWizardInstaller = new WebSetupWizardPluginInstaller($this->console);
77+
return $setupWizardInstaller->doVarInstall();
7278
} else {
73-
Console::error("'$operation' is not a supported operation for ".static::NAME);
79+
$this->console->error("'$operation' is not a supported operation for ".static::NAME);
7480
return 1;
7581
}
7682
}

src/Magento/ComposerRootUpdatePlugin/Plugin/PluginDefinition.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Composer\Plugin\Capable;
1616
use Composer\Plugin\PluginInterface;;
1717
use Magento\ComposerRootUpdatePlugin\Setup\WebSetupWizardPluginInstaller;
18+
use Magento\ComposerRootUpdatePlugin\Utils\Console;
1819

1920
/**
2021
* Composer's entry point for the plugin, defines the command provider and Web Setup Wizard Installer's event triggers
@@ -60,7 +61,8 @@ public function packageUpdate(PackageEvent $event)
6061
{
6162
// Safeguard against the source file being removed before the event is triggered
6263
if (class_exists('\Magento\ComposerRootUpdatePlugin\Setup\WebSetupWizardPluginInstaller')) {
63-
WebSetupWizardPluginInstaller::packageEvent($event);
64+
$setupWizardInstaller = new WebSetupWizardPluginInstaller(new Console($event->getIO()));
65+
$setupWizardInstaller->packageEvent($event);
6466
}
6567
}
6668
}

src/Magento/ComposerRootUpdatePlugin/Setup/InstallData.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66

77
namespace Magento\ComposerRootUpdatePlugin\Setup;
88

9+
use Composer\IO\ConsoleIO;
10+
use Magento\ComposerRootUpdatePlugin\Utils\Console;
911
use Magento\Framework\Setup\InstallDataInterface;
1012
use Magento\Framework\Setup\ModuleContextInterface;
1113
use Magento\Framework\Setup\ModuleDataSetupInterface;
14+
use Symfony\Component\Console\Helper\DebugFormatterHelper;
15+
use Symfony\Component\Console\Helper\FormatterHelper;
16+
use Symfony\Component\Console\Helper\HelperSet;
17+
use Symfony\Component\Console\Helper\ProcessHelper;
18+
use Symfony\Component\Console\Helper\QuestionHelper;
19+
use Symfony\Component\Console\Input\ArrayInput;
20+
use Symfony\Component\Console\Output\ConsoleOutput;
21+
use Symfony\Component\Console\Output\OutputInterface;
1222

1323
/**
1424
* Magento module hook to attach plugin installation functionality to `magento setup` operations
@@ -24,6 +34,16 @@ class InstallData implements InstallDataInterface
2434
*/
2535
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
2636
{
27-
WebSetupWizardPluginInstaller::doVarInstall();
37+
$io = new ConsoleIO(new ArrayInput([]),
38+
new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG),
39+
new HelperSet([
40+
new FormatterHelper(),
41+
new DebugFormatterHelper(),
42+
new ProcessHelper(),
43+
new QuestionHelper()
44+
])
45+
);
46+
$setupWizardInstaller = new WebSetupWizardPluginInstaller(new Console($io));
47+
$setupWizardInstaller->doVarInstall();
2848
}
2949
}

src/Magento/ComposerRootUpdatePlugin/Setup/RecurringData.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66

77
namespace Magento\ComposerRootUpdatePlugin\Setup;
88

9+
use Composer\IO\ConsoleIO;
10+
use Magento\ComposerRootUpdatePlugin\Utils\Console;
911
use Magento\Framework\Setup\InstallDataInterface;
1012
use Magento\Framework\Setup\ModuleContextInterface;
1113
use Magento\Framework\Setup\ModuleDataSetupInterface;
14+
use Symfony\Component\Console\Helper\DebugFormatterHelper;
15+
use Symfony\Component\Console\Helper\FormatterHelper;
16+
use Symfony\Component\Console\Helper\HelperSet;
17+
use Symfony\Component\Console\Helper\ProcessHelper;
18+
use Symfony\Component\Console\Helper\QuestionHelper;
19+
use Symfony\Component\Console\Input\ArrayInput;
20+
use Symfony\Component\Console\Output\ConsoleOutput;
21+
use Symfony\Component\Console\Output\OutputInterface;
1222

1323
/**
1424
* Magento module hook to attach plugin installation functionality to `magento setup` operations
@@ -24,6 +34,16 @@ class RecurringData implements InstallDataInterface
2434
*/
2535
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
2636
{
27-
WebSetupWizardPluginInstaller::doVarInstall();
37+
$io = new ConsoleIO(new ArrayInput([]),
38+
new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG),
39+
new HelperSet([
40+
new FormatterHelper(),
41+
new DebugFormatterHelper(),
42+
new ProcessHelper(),
43+
new QuestionHelper()
44+
])
45+
);
46+
$setupWizardInstaller = new WebSetupWizardPluginInstaller(new Console($io));
47+
$setupWizardInstaller->doVarInstall();
2848
}
2949
}

src/Magento/ComposerRootUpdatePlugin/Setup/UpgradeData.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66

77
namespace Magento\ComposerRootUpdatePlugin\Setup;
88

9+
use Composer\IO\ConsoleIO;
10+
use Magento\ComposerRootUpdatePlugin\Utils\Console;
911
use Magento\Framework\Setup\ModuleContextInterface;
1012
use Magento\Framework\Setup\ModuleDataSetupInterface;
1113
use Magento\Framework\Setup\UpgradeDataInterface;
14+
use Symfony\Component\Console\Helper\DebugFormatterHelper;
15+
use Symfony\Component\Console\Helper\FormatterHelper;
16+
use Symfony\Component\Console\Helper\HelperSet;
17+
use Symfony\Component\Console\Helper\ProcessHelper;
18+
use Symfony\Component\Console\Helper\QuestionHelper;
19+
use Symfony\Component\Console\Input\ArrayInput;
20+
use Symfony\Component\Console\Output\ConsoleOutput;
21+
use Symfony\Component\Console\Output\OutputInterface;
1222

1323
/**
1424
* Magento module hook to attach plugin installation functionality to `magento setup` operations
@@ -24,6 +34,16 @@ class UpgradeData implements UpgradeDataInterface
2434
*/
2535
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
2636
{
27-
WebSetupWizardPluginInstaller::doVarInstall();
37+
$io = new ConsoleIO(new ArrayInput([]),
38+
new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG),
39+
new HelperSet([
40+
new FormatterHelper(),
41+
new DebugFormatterHelper(),
42+
new ProcessHelper(),
43+
new QuestionHelper()
44+
])
45+
);
46+
$setupWizardInstaller = new WebSetupWizardPluginInstaller(new Console($io));
47+
$setupWizardInstaller->doVarInstall();
2848
}
2949
}

0 commit comments

Comments
 (0)