10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
22 use Symfony\Component\Console\Command\Command;
23 use Symfony\Component\Console\Helper\ProgressBar;
33 const NAME =
'setup:di:compile';
38 private $deploymentConfig;
43 private $objectManager;
53 private $directoryList;
63 private $excludedPathsList;
73 private $componentRegistrar;
96 $this->directoryList = $directoryList;
97 $this->objectManager = $objectManagerProvider->
get();
98 $this->taskManager = $taskManager;
100 $this->fileDriver = $fileDriver;
102 parent::__construct();
110 $this->setName(self::NAME)
112 'Generates DI configuration and all missing classes that can be auto-generated' 122 private function checkEnvironment()
127 $messages[] =
'You cannot run this command because modules are not enabled. You can enable modules by' 128 .
' running the \'module:enable --all\' command.';
137 protected function execute(InputInterface $input, OutputInterface
$output)
139 $errors = $this->checkEnvironment();
153 $this->objectManager->get(\
Magento\Framework\
App\Cache::class)->clean();
154 $compiledPathsList = [
155 'application' => $modulePaths,
156 'library' => $libraryPaths,
157 'setup' => $setupPath,
158 'generated_helpers' => $generationPath
161 $this->excludedPathsList = [
162 'application' => $this->getExcludedModulePaths($modulePaths),
163 'framework' => $this->getExcludedLibraryPaths($libraryPaths),
164 'setup' => $this->getExcludedSetupPaths($setupPath),
166 $this->configureObjectManager(
$output);
168 $operations = $this->getOperationsConfiguration($compiledPathsList);
171 $this->cleanupFilesystem(
178 $this->taskManager->addOperation(
185 $progressBar = $this->objectManager->create(
186 \Symfony\Component\Console\Helper\ProgressBar::class,
192 $progressBar->setFormat(
193 '<info>%message%</info> %current%/%max% [%bar%] %percent:3s%% %elapsed% %memory:6s%' 195 $output->writeln(
'<info>Compilation was started.</info>');
196 $progressBar->start();
197 $progressBar->display();
199 $this->taskManager->process(
200 function (OperationInterface $operation) use ($progressBar) {
201 $progressBar->setMessage($operation->getName() .
'...');
202 $progressBar->display();
204 function (OperationInterface $operation) use ($progressBar) {
205 $progressBar->advance();
209 $progressBar->finish();
211 $output->writeln(
'<info>Generated code and dependency injection configuration successfully.</info>');
212 }
catch (OperationException $e) {
213 $output->writeln(
'<error>' . $e->getMessage() .
'</error>');
226 private function getExcludedModulePaths(array $modulePaths)
228 $modulesByBasePath = [];
229 foreach ($modulePaths as $modulePath) {
230 $moduleDir = basename($modulePath);
231 $vendorPath = dirname($modulePath);
233 $basePath = dirname($vendorPath);
234 $modulesByBasePath[$basePath][
$vendorDir][] = $moduleDir;
237 $basePathsRegExps = [];
238 foreach ($modulesByBasePath as $basePath => $vendorPaths) {
239 $vendorPathsRegExps = [];
240 foreach ($vendorPaths as
$vendorDir => $vendorModules) {
242 .
'/(?:' . join(
'|', $vendorModules) .
')';
244 $basePathsRegExps[] = preg_quote($basePath,
'#')
245 .
'/(?:' . join(
'|', $vendorPathsRegExps) .
')';
248 $excludedModulePaths = [
249 '#^(?:' . join(
'|', $basePathsRegExps) .
')/Test#',
250 '#^(?:' . join(
'|', $basePathsRegExps) .
')/tests#',
252 return $excludedModulePaths;
261 private function getExcludedLibraryPaths(array $libraryPaths)
267 $excludedLibraryPaths = [
268 '#^(?:' . join(
'|', $libraryPaths) .
')/([\\w]+/)?Test#',
269 '#^(?:' . join(
'|', $libraryPaths) .
')/([\\w]+/)?tests#',
271 return $excludedLibraryPaths;
280 private function getExcludedSetupPaths($setupPath)
283 '#^(?:' . preg_quote($setupPath,
'#') .
')(/[\\w]+)*/Test#' 293 private function cleanupFilesystem($directoryCodeList)
295 foreach ($directoryCodeList as
$code) {
296 $this->filesystem->getDirectoryWrite(
$code)->delete();
306 private function configureObjectManager(OutputInterface
$output)
308 $this->objectManager->configure(
310 'preferences' => [\
Magento\Setup\Module\Di\Compiler\Config\WriterInterface::class =>
311 \
Magento\Setup\Module\Di\Compiler\Config\
Writer\Filesystem::class,
312 ], \
Magento\Setup\Module\Di\Compiler\Config\ModificationChain::class => [
314 'modificationsList' => [
317 \
Magento\Setup\Module\Di\Compiler\Config\Chain\BackslashTrim::class
319 'PreferencesResolving' => [
321 \
Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving::class
323 'InterceptorSubstitution' => [
325 \
Magento\Setup\Module\Di\Compiler\Config\Chain\InterceptorSubstitution::class
327 'InterceptionPreferencesResolving' => [
328 'instance' => \
Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving::class
332 ], \
Magento\Setup\Module\Di\Code\Generator\PluginList::class => [
335 'instance' => \
Magento\Framework\
App\Interception\Cache\CompiledConfig::class
338 ], \
Magento\Setup\Module\Di\Code\Reader\ClassesScanner::class => [
340 'excludePatterns' => $this->excludedPathsList
342 ], \
Magento\Setup\Module\Di\Compiler\Log\
Writer\Console::class => [
357 private function getOperationsConfiguration(
358 array $compiledPathsList
360 $excludePatterns = [];
361 foreach ($this->excludedPathsList as $excludedPaths) {
362 $excludePatterns = array_merge($excludedPaths, $excludePatterns);
368 'paths' => $compiledPathsList[
'application'],
373 $compiledPathsList[
'application'],
374 $compiledPathsList[
'library'],
375 $compiledPathsList[
'setup'],
376 $compiledPathsList[
'generated_helpers'],
378 'filePatterns' => [
'php' =>
'/\.php$/'],
379 'excludePatterns' => $excludePatterns,
382 'intercepted_paths' => [
383 $compiledPathsList[
'application'],
384 $compiledPathsList[
'library'],
385 $compiledPathsList[
'generated_helpers'],
387 'path_to_store' => $compiledPathsList[
'generated_helpers'],
390 $compiledPathsList[
'application'],
391 $compiledPathsList[
'library'],
392 $compiledPathsList[
'generated_helpers'],
395 $compiledPathsList[
'application'],
396 $compiledPathsList[
'library'],
397 $compiledPathsList[
'generated_helpers'],
const DATA_ATTRIBUTES_GENERATOR
const AREA_CONFIG_GENERATOR
const REPOSITORY_GENERATOR
if(!file_exists(VENDOR_PATH)) $vendorDir
__construct(DeploymentConfig $deploymentConfig, DirectoryList $directoryList, Manager $taskManager, ObjectManagerProvider $objectManagerProvider, Filesystem $filesystem, DriverInterface $fileDriver, ComponentRegistrar $componentRegistrar)
const APPLICATION_CODE_GENERATOR
if(isset($opts->l)) $libraryPath