/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $errors = $this->checkEnvironment();
     if ($errors) {
         foreach ($errors as $line) {
             $output->writeln($line);
         }
         // we must have an exit code higher than zero to indicate something was wrong
         return \Magento\Framework\Console\Cli::RETURN_FAILURE;
     }
     $modulePaths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);
     $libraryPaths = $this->componentRegistrar->getPaths(ComponentRegistrar::LIBRARY);
     $generationPath = $this->directoryList->getPath(DirectoryList::GENERATION);
     $this->objectManager->get('Magento\\Framework\\App\\Cache')->clean();
     $compiledPathsList = ['application' => $modulePaths, 'library' => $libraryPaths, 'generated_helpers' => $generationPath];
     $excludedModulePaths = [];
     foreach ($modulePaths as $appCodePath) {
         $excludedModulePaths[] = '#^' . $appCodePath . '/Test#';
     }
     $excludedLibraryPaths = [];
     foreach ($libraryPaths as $libraryPath) {
         $excludedLibraryPaths[] = '#^' . $libraryPath . '/([\\w]+/)?Test#';
     }
     $this->excludedPathsList = ['application' => $excludedModulePaths, 'framework' => $excludedLibraryPaths];
     $this->configureObjectManager($output);
     $operations = $this->getOperationsConfiguration($compiledPathsList);
     try {
         $this->cleanupFilesystem([DirectoryList::CACHE, DirectoryList::DI]);
         foreach ($operations as $operationCode => $arguments) {
             $this->taskManager->addOperation($operationCode, $arguments);
         }
         /** @var ProgressBar $progressBar */
         $progressBar = $this->objectManager->create('Symfony\\Component\\Console\\Helper\\ProgressBar', ['output' => $output, 'max' => count($operations)]);
         $progressBar->setFormat('<info>%message%</info> %current%/%max% [%bar%] %percent:3s%% %elapsed% %memory:6s%');
         $output->writeln('<info>Compilation was started.</info>');
         $progressBar->start();
         $progressBar->display();
         $this->taskManager->process(function (OperationInterface $operation) use($progressBar) {
             $progressBar->setMessage($operation->getName() . '...');
             $progressBar->display();
         }, function (OperationInterface $operation) use($progressBar) {
             $progressBar->advance();
         });
         $progressBar->finish();
         $output->writeln('');
         $output->writeln('<info>Generated code and dependency injection configuration successfully.</info>');
     } catch (OperationException $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         // we must have an exit code higher than zero to indicate something was wrong
         return \Magento\Framework\Console\Cli::RETURN_FAILURE;
     }
 }
Exemple #2
0
    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $appCodePath = $this->directoryList->getPath(DirectoryList::MODULES);
        $libraryPath = $this->directoryList->getPath(DirectoryList::LIB_INTERNAL);
        $generationPath = $this->directoryList->getPath(DirectoryList::GENERATION);
        if (!$this->deploymentConfig->isAvailable()) {
            $output->writeln('You cannot run this command because the Magento application is not installed.');
            return;
        }
        $this->objectManager->get('Magento\Framework\App\Cache')->clean();
        $compiledPathsList = [
            'application' => $appCodePath,
            'library' => $libraryPath . '/Magento/Framework',
            'generated_helpers' => $generationPath
        ];
        $this->excludedPathsList = [
            'application' => '#^' . $appCodePath . '/[\\w]+/[\\w]+/Test#',
            'framework' => '#^' . $libraryPath . '/[\\w]+/[\\w]+/([\\w]+/)?Test#'
        ];
        $dataAttributesIncludePattern = [
            'extension_attributes' => '/\/etc\/([a-zA-Z_]*\/extension_attributes|extension_attributes)\.xml$/'
        ];
        $this->configureObjectManager($output);

        $operations = [
            OperationFactory::REPOSITORY_GENERATOR => [
                'path' => $compiledPathsList['application'],
                'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/']
            ],
            OperationFactory::DATA_ATTRIBUTES_GENERATOR => [
                'path' => $compiledPathsList['application'],
                'filePatterns' => $dataAttributesIncludePattern
            ],
            OperationFactory::APPLICATION_CODE_GENERATOR => [
                $compiledPathsList['application'],
                $compiledPathsList['library'],
                $compiledPathsList['generated_helpers'],
            ],
            OperationFactory::INTERCEPTION => [
                    'intercepted_paths' => [
                        $compiledPathsList['application'],
                        $compiledPathsList['library'],
                        $compiledPathsList['generated_helpers'],
                    ],
                    'path_to_store' => $compiledPathsList['generated_helpers'],
            ],
            OperationFactory::AREA_CONFIG_GENERATOR => [
                $compiledPathsList['application'],
                $compiledPathsList['library'],
                $compiledPathsList['generated_helpers'],
            ],
            OperationFactory::INTERCEPTION_CACHE => [
                $compiledPathsList['application'],
                $compiledPathsList['library'],
                $compiledPathsList['generated_helpers'],
            ]
        ];

        try {
            $this->cleanupFilesystem(
                [
                    DirectoryList::CACHE,
                    DirectoryList::GENERATION,
                    DirectoryList::DI,
                ]
            );
            foreach ($operations as $operationCode => $arguments) {
                $this->taskManager->addOperation(
                    $operationCode,
                    $arguments
                );
            }
            $this->taskManager->process();
            $output->writeln('<info>Generated code and dependency injection configuration successfully.</info>');
        } catch (OperationException $e) {
            $output->writeln('<error>' . $e->getMessage() . '</error>');
        }
    }
    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $appCodePath = $this->directoryList->getPath(DirectoryList::MODULES);
        $libraryPath = $this->directoryList->getPath(DirectoryList::LIB_INTERNAL);
        $generationPath = $this->directoryList->getPath(DirectoryList::GENERATION);
        if (!$this->deploymentConfig->isAvailable()) {
            $output->writeln('You cannot run this command because the Magento application is not installed.');
            return;
        }
        $this->objectManager->get('Magento\Framework\App\Cache')->clean();
        $compiledPathsList = [
            'application' => $appCodePath,
            'library' => $libraryPath . '/Magento/Framework',
            'generated_helpers' => $generationPath
        ];
        $this->excludedPathsList = [
            'application' => '#^' . $appCodePath . '/[\\w]+/[\\w]+/Test#',
            'framework' => '#^' . $libraryPath . '/[\\w]+/[\\w]+/([\\w]+/)?Test#'
        ];
        $dataAttributesIncludePattern = [
            'extension_attributes' => '/\/etc\/([a-zA-Z_]*\/extension_attributes|extension_attributes)\.xml$/'
        ];
        $this->configureObjectManager($output);

        $operations = $this->getOperationsConfiguration(
            $compiledPathsList,
            $dataAttributesIncludePattern
        );

        try {
            $this->cleanupFilesystem(
                [
                    DirectoryList::CACHE,
                    DirectoryList::GENERATION,
                    DirectoryList::DI,
                ]
            );
            foreach ($operations as $operationCode => $arguments) {
                $this->taskManager->addOperation(
                    $operationCode,
                    $arguments
                );
            }

            /** @var ProgressBar $progressBar */
            $progressBar = $this->objectManager->create(
                'Symfony\Component\Console\Helper\ProgressBar',
                [
                    'output' => $output,
                    'max' => count($operations)
                ]
            );
            $progressBar->setFormat(
                '<info>%message%</info> %current%/%max% [%bar%] %percent:3s%% %elapsed% %memory:6s%'
            );
            $output->writeln('<info>Compilation was started.</info>');
            $progressBar->start();
            $progressBar->display();

            $this->taskManager->process(
                function (OperationInterface $operation) use ($progressBar) {
                    $progressBar->setMessage($operation->getName() . '...');
                    $progressBar->display();
                },
                function (OperationInterface $operation) use ($progressBar) {
                    $progressBar->advance();
                }
            );

            $progressBar->finish();
            $output->writeln('');
            $output->writeln('<info>Generated code and dependency injection configuration successfully.</info>');
        } catch (OperationException $e) {
            $output->writeln('<error>' . $e->getMessage() . '</error>');
        }
    }