diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php index 76f537185aab4..745c0e5b0d721 100644 --- a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php @@ -6,24 +6,33 @@ namespace Magento\Setup\Console\Command; -use Magento\Framework\App\ObjectManager; -use Magento\Framework\Filesystem\DriverInterface; -use Magento\Framework\Filesystem\Io\File; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Magento\Framework\Filesystem; -use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\Interception\Cache\CompiledConfig; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\ObjectManager\ConfigWriterInterface; use Magento\Framework\Component\ComponentRegistrar; use Magento\Framework\Config\ConfigOptionsListConstants; +use Magento\Framework\Console\Cli; +use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\DriverInterface; +use Magento\Framework\Filesystem\Io\File; use Magento\Setup\Model\ObjectManagerProvider; use Magento\Setup\Module\Di\App\Task\Manager; -use Magento\Setup\Module\Di\App\Task\OperationFactory; use Magento\Setup\Module\Di\App\Task\OperationException; +use Magento\Setup\Module\Di\App\Task\OperationFactory; use Magento\Setup\Module\Di\App\Task\OperationInterface; +use Magento\Setup\Module\Di\Code\Generator\PluginList; +use Magento\Setup\Module\Di\Code\Reader\ClassesScanner; +use Magento\Setup\Module\Di\Compiler\Config\Chain\BackslashTrim; +use Magento\Setup\Module\Di\Compiler\Config\Chain\InterceptorSubstitution; +use Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving; +use Magento\Setup\Module\Di\Compiler\Config\ModificationChain; +use Magento\Setup\Module\Di\Compiler\Log\Writer\Console; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; -use Magento\Framework\Console\Cli; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; /** * Command to run compile in single-tenant mode @@ -156,20 +165,26 @@ protected function execute(InputInterface $input, OutputInterface $output) } $modulePaths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE); + $moduleStatuses = $this->deploymentConfig->get(ConfigOptionsListConstants::KEY_MODULES); + + $modulePathsEnabled = array_filter($modulePaths, function ($path, $module) use ($moduleStatuses) { + return ($moduleStatuses[$module] ?? 0) === 1; + }, ARRAY_FILTER_USE_BOTH); + $libraryPaths = $this->componentRegistrar->getPaths(ComponentRegistrar::LIBRARY); $setupPath = $this->directoryList->getPath(DirectoryList::SETUP); $generationPath = $this->directoryList->getPath(DirectoryList::GENERATED_CODE); $this->objectManager->get(\Magento\Framework\App\Cache::class)->clean(); $compiledPathsList = [ - 'application' => $modulePaths, + 'application' => $modulePathsEnabled, 'library' => $libraryPaths, 'setup' => $setupPath, 'generated_helpers' => $generationPath ]; $this->excludedPathsList = [ - 'application' => $this->getExcludedModulePaths($modulePaths), + 'application' => $this->getExcludedModulePaths($modulePathsEnabled), 'framework' => $this->getExcludedLibraryPaths($libraryPaths), 'setup' => $this->getExcludedSetupPaths($setupPath), ]; @@ -207,11 +222,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $progressBar->display(); $this->taskManager->process( - function (OperationInterface $operation) use ($progressBar) { + function (OperationInterface $operation) use ($progressBar): void { $progressBar->setMessage($operation->getName() . '...'); $progressBar->display(); }, - function (OperationInterface $operation) use ($progressBar) { + function (OperationInterface $operation) use ($progressBar): void { $progressBar->advance(); } ); @@ -327,39 +342,35 @@ private function configureObjectManager(OutputInterface $output) { $this->objectManager->configure( [ - 'preferences' => [\Magento\Framework\App\ObjectManager\ConfigWriterInterface::class => - \Magento\Framework\App\ObjectManager\ConfigWriter\Filesystem::class, - ], \Magento\Setup\Module\Di\Compiler\Config\ModificationChain::class => [ + 'preferences' => [ConfigWriterInterface::class => ObjectManager\ConfigWriter\Filesystem::class, + ], ModificationChain::class => [ 'arguments' => [ 'modificationsList' => [ 'BackslashTrim' => [ - 'instance' => - \Magento\Setup\Module\Di\Compiler\Config\Chain\BackslashTrim::class + 'instance' => BackslashTrim::class ], 'PreferencesResolving' => [ - 'instance' => - \Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving::class + 'instance' => PreferencesResolving::class ], 'InterceptorSubstitution' => [ - 'instance' => - \Magento\Setup\Module\Di\Compiler\Config\Chain\InterceptorSubstitution::class + 'instance' => InterceptorSubstitution::class ], 'InterceptionPreferencesResolving' => [ - 'instance' => \Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving::class + 'instance' => PreferencesResolving::class ], ] ] - ], \Magento\Setup\Module\Di\Code\Generator\PluginList::class => [ + ], PluginList::class => [ 'arguments' => [ 'cache' => [ - 'instance' => \Magento\Framework\App\Interception\Cache\CompiledConfig::class + 'instance' => CompiledConfig::class ] ] - ], \Magento\Setup\Module\Di\Code\Reader\ClassesScanner::class => [ + ], ClassesScanner::class => [ 'arguments' => [ 'excludePatterns' => $this->excludedPathsList ] - ], \Magento\Setup\Module\Di\Compiler\Log\Writer\Console::class => [ + ], Console::class => [ 'arguments' => [ 'output' => $output, ] diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php index 00f04dbf9799d..f638321d6fe23 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php @@ -1,7 +1,7 @@ expects($this->atLeastOnce())->method('delete'); $this->filesystemMock->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory); - $this->deploymentConfigMock->expects($this->once()) + $this->deploymentConfigMock->expects($this->exactly(2)) ->method('get') ->with(ConfigOptionsListConstants::KEY_MODULES) - ->willReturn(['Magento_Catalog' => 1]); + ->willReturn( + [ + 'Magento_Catalog' => 1, + 'Module_Test' => 0 + ] + ); + $this->componentRegistrarMock->expects($this->exactly(2))->method('getPaths'); + $progressBar = new ProgressBar($this->outputMock); $this->objectManagerMock->expects($this->once())->method('configure'); @@ -181,25 +188,21 @@ public function testExecute() ->with(ProgressBar::class) ->willReturn($progressBar); + $operations = [ + OperationFactory::REPOSITORY_GENERATOR, + OperationFactory::DATA_ATTRIBUTES_GENERATOR, + OperationFactory::APPLICATION_CODE_GENERATOR, + OperationFactory::INTERCEPTION, + OperationFactory::AREA_CONFIG_GENERATOR, + OperationFactory::INTERCEPTION_CACHE, + OperationFactory::APPLICATION_ACTION_LIST_GENERATOR, + OperationFactory::PLUGIN_LIST_GENERATOR, + ]; $this->managerMock->expects($this->exactly(9))->method('addOperation') - ->willReturnCallback(function ($arg1, $arg2) { + ->willReturnCallback(function ($arg1, $arg2) use ($operations) { if ($arg1 == OperationFactory::PROXY_GENERATOR && empty($arg2)) { return null; - } elseif ($arg1 == OperationFactory::REPOSITORY_GENERATOR) { - return null; - } elseif ($arg1 == OperationFactory::DATA_ATTRIBUTES_GENERATOR) { - return null; - } elseif ($arg1 == OperationFactory::APPLICATION_CODE_GENERATOR) { - return null; - } elseif ($arg1 == OperationFactory::INTERCEPTION) { - return null; - } elseif ($arg1 == OperationFactory::AREA_CONFIG_GENERATOR) { - return null; - } elseif ($arg1 == OperationFactory::INTERCEPTION_CACHE) { - return null; - } elseif ($arg1 == OperationFactory::APPLICATION_ACTION_LIST_GENERATOR) { - return null; - } elseif ($arg1 == OperationFactory::PLUGIN_LIST_GENERATOR) { + } elseif (in_array($arg1, $operations)) { return null; } });