Skip to content

Commit ade8ea8

Browse files
Merge remote-tracking branch '39723/issue38241' into blprs
2 parents 667c0ad + 3cd8bf5 commit ade8ea8

File tree

2 files changed

+61
-47
lines changed

2 files changed

+61
-47
lines changed

setup/src/Magento/Setup/Console/Command/DiCompileCommand.php

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,33 @@
66

77
namespace Magento\Setup\Console\Command;
88

9-
use Magento\Framework\App\ObjectManager;
10-
use Magento\Framework\Filesystem\DriverInterface;
11-
use Magento\Framework\Filesystem\Io\File;
12-
use Symfony\Component\Console\Input\InputInterface;
13-
use Symfony\Component\Console\Output\OutputInterface;
14-
use Magento\Framework\Filesystem;
15-
use Magento\Framework\App\Filesystem\DirectoryList;
169
use Magento\Framework\App\DeploymentConfig;
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\App\Interception\Cache\CompiledConfig;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\App\ObjectManager\ConfigWriterInterface;
1714
use Magento\Framework\Component\ComponentRegistrar;
1815
use Magento\Framework\Config\ConfigOptionsListConstants;
16+
use Magento\Framework\Console\Cli;
17+
use Magento\Framework\Filesystem;
18+
use Magento\Framework\Filesystem\DriverInterface;
19+
use Magento\Framework\Filesystem\Io\File;
1920
use Magento\Setup\Model\ObjectManagerProvider;
2021
use Magento\Setup\Module\Di\App\Task\Manager;
21-
use Magento\Setup\Module\Di\App\Task\OperationFactory;
2222
use Magento\Setup\Module\Di\App\Task\OperationException;
23+
use Magento\Setup\Module\Di\App\Task\OperationFactory;
2324
use Magento\Setup\Module\Di\App\Task\OperationInterface;
25+
use Magento\Setup\Module\Di\Code\Generator\PluginList;
26+
use Magento\Setup\Module\Di\Code\Reader\ClassesScanner;
27+
use Magento\Setup\Module\Di\Compiler\Config\Chain\BackslashTrim;
28+
use Magento\Setup\Module\Di\Compiler\Config\Chain\InterceptorSubstitution;
29+
use Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving;
30+
use Magento\Setup\Module\Di\Compiler\Config\ModificationChain;
31+
use Magento\Setup\Module\Di\Compiler\Log\Writer\Console;
2432
use Symfony\Component\Console\Command\Command;
2533
use Symfony\Component\Console\Helper\ProgressBar;
26-
use Magento\Framework\Console\Cli;
34+
use Symfony\Component\Console\Input\InputInterface;
35+
use Symfony\Component\Console\Output\OutputInterface;
2736

2837
/**
2938
* Command to run compile in single-tenant mode
@@ -156,20 +165,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
156165
}
157166

158167
$modulePaths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);
168+
$moduleStatuses = $this->deploymentConfig->get(ConfigOptionsListConstants::KEY_MODULES);
169+
170+
$modulePathsEnabled = array_filter($modulePaths, function ($path, $module) use ($moduleStatuses) {
171+
return ($moduleStatuses[$module] ?? 0) === 1;
172+
}, ARRAY_FILTER_USE_BOTH);
173+
159174
$libraryPaths = $this->componentRegistrar->getPaths(ComponentRegistrar::LIBRARY);
160175
$setupPath = $this->directoryList->getPath(DirectoryList::SETUP);
161176
$generationPath = $this->directoryList->getPath(DirectoryList::GENERATED_CODE);
162177

163178
$this->objectManager->get(\Magento\Framework\App\Cache::class)->clean();
164179
$compiledPathsList = [
165-
'application' => $modulePaths,
180+
'application' => $modulePathsEnabled,
166181
'library' => $libraryPaths,
167182
'setup' => $setupPath,
168183
'generated_helpers' => $generationPath
169184
];
170185

171186
$this->excludedPathsList = [
172-
'application' => $this->getExcludedModulePaths($modulePaths),
187+
'application' => $this->getExcludedModulePaths($modulePathsEnabled),
173188
'framework' => $this->getExcludedLibraryPaths($libraryPaths),
174189
'setup' => $this->getExcludedSetupPaths($setupPath),
175190
];
@@ -207,11 +222,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
207222
$progressBar->display();
208223

209224
$this->taskManager->process(
210-
function (OperationInterface $operation) use ($progressBar) {
225+
function (OperationInterface $operation) use ($progressBar): void {
211226
$progressBar->setMessage($operation->getName() . '...');
212227
$progressBar->display();
213228
},
214-
function (OperationInterface $operation) use ($progressBar) {
229+
function (OperationInterface $operation) use ($progressBar): void {
215230
$progressBar->advance();
216231
}
217232
);
@@ -327,39 +342,35 @@ private function configureObjectManager(OutputInterface $output)
327342
{
328343
$this->objectManager->configure(
329344
[
330-
'preferences' => [\Magento\Framework\App\ObjectManager\ConfigWriterInterface::class =>
331-
\Magento\Framework\App\ObjectManager\ConfigWriter\Filesystem::class,
332-
], \Magento\Setup\Module\Di\Compiler\Config\ModificationChain::class => [
345+
'preferences' => [ConfigWriterInterface::class => ObjectManager\ConfigWriter\Filesystem::class,
346+
], ModificationChain::class => [
333347
'arguments' => [
334348
'modificationsList' => [
335349
'BackslashTrim' => [
336-
'instance' =>
337-
\Magento\Setup\Module\Di\Compiler\Config\Chain\BackslashTrim::class
350+
'instance' => BackslashTrim::class
338351
],
339352
'PreferencesResolving' => [
340-
'instance' =>
341-
\Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving::class
353+
'instance' => PreferencesResolving::class
342354
],
343355
'InterceptorSubstitution' => [
344-
'instance' =>
345-
\Magento\Setup\Module\Di\Compiler\Config\Chain\InterceptorSubstitution::class
356+
'instance' => InterceptorSubstitution::class
346357
],
347358
'InterceptionPreferencesResolving' => [
348-
'instance' => \Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving::class
359+
'instance' => PreferencesResolving::class
349360
],
350361
]
351362
]
352-
], \Magento\Setup\Module\Di\Code\Generator\PluginList::class => [
363+
], PluginList::class => [
353364
'arguments' => [
354365
'cache' => [
355-
'instance' => \Magento\Framework\App\Interception\Cache\CompiledConfig::class
366+
'instance' => CompiledConfig::class
356367
]
357368
]
358-
], \Magento\Setup\Module\Di\Code\Reader\ClassesScanner::class => [
369+
], ClassesScanner::class => [
359370
'arguments' => [
360371
'excludePatterns' => $this->excludedPathsList
361372
]
362-
], \Magento\Setup\Module\Di\Compiler\Log\Writer\Console::class => [
373+
], Console::class => [
363374
'arguments' => [
364375
'output' => $output,
365376
]

setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -168,10 +168,17 @@ public function testExecute()
168168
$writeDirectory->expects($this->atLeastOnce())->method('delete');
169169
$this->filesystemMock->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);
170170

171-
$this->deploymentConfigMock->expects($this->once())
171+
$this->deploymentConfigMock->expects($this->exactly(2))
172172
->method('get')
173173
->with(ConfigOptionsListConstants::KEY_MODULES)
174-
->willReturn(['Magento_Catalog' => 1]);
174+
->willReturn(
175+
[
176+
'Magento_Catalog' => 1,
177+
'Module_Test' => 0
178+
]
179+
);
180+
$this->componentRegistrarMock->expects($this->exactly(2))->method('getPaths');
181+
175182
$progressBar = new ProgressBar($this->outputMock);
176183

177184
$this->objectManagerMock->expects($this->once())->method('configure');
@@ -181,25 +188,21 @@ public function testExecute()
181188
->with(ProgressBar::class)
182189
->willReturn($progressBar);
183190

191+
$operations = [
192+
OperationFactory::REPOSITORY_GENERATOR,
193+
OperationFactory::DATA_ATTRIBUTES_GENERATOR,
194+
OperationFactory::APPLICATION_CODE_GENERATOR,
195+
OperationFactory::INTERCEPTION,
196+
OperationFactory::AREA_CONFIG_GENERATOR,
197+
OperationFactory::INTERCEPTION_CACHE,
198+
OperationFactory::APPLICATION_ACTION_LIST_GENERATOR,
199+
OperationFactory::PLUGIN_LIST_GENERATOR,
200+
];
184201
$this->managerMock->expects($this->exactly(9))->method('addOperation')
185-
->willReturnCallback(function ($arg1, $arg2) {
202+
->willReturnCallback(function ($arg1, $arg2) use ($operations) {
186203
if ($arg1 == OperationFactory::PROXY_GENERATOR && empty($arg2)) {
187204
return null;
188-
} elseif ($arg1 == OperationFactory::REPOSITORY_GENERATOR) {
189-
return null;
190-
} elseif ($arg1 == OperationFactory::DATA_ATTRIBUTES_GENERATOR) {
191-
return null;
192-
} elseif ($arg1 == OperationFactory::APPLICATION_CODE_GENERATOR) {
193-
return null;
194-
} elseif ($arg1 == OperationFactory::INTERCEPTION) {
195-
return null;
196-
} elseif ($arg1 == OperationFactory::AREA_CONFIG_GENERATOR) {
197-
return null;
198-
} elseif ($arg1 == OperationFactory::INTERCEPTION_CACHE) {
199-
return null;
200-
} elseif ($arg1 == OperationFactory::APPLICATION_ACTION_LIST_GENERATOR) {
201-
return null;
202-
} elseif ($arg1 == OperationFactory::PLUGIN_LIST_GENERATOR) {
205+
} elseif (in_array($arg1, $operations)) {
203206
return null;
204207
}
205208
});

0 commit comments

Comments
 (0)