Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractModuleCommand.php
Go to the documentation of this file.
1 <?php
7 
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
14 
19 {
23  const INPUT_KEY_MODULES = 'module';
24  const INPUT_KEY_CLEAR_STATIC_CONTENT = 'clear-static-content';
25 
31  protected $objectManager;
32 
38  public function __construct(ObjectManagerProvider $objectManagerProvider)
39  {
40  $this->objectManager = $objectManagerProvider->get();
41  parent::__construct();
42  }
43 
47  protected function configure()
48  {
49  $this->addArgument(
50  self::INPUT_KEY_MODULES,
51  InputArgument::IS_ARRAY | ($this->isModuleRequired() ? InputArgument::REQUIRED : InputArgument::OPTIONAL),
52  'Name of the module'
53  );
54  $this->addOption(
55  self::INPUT_KEY_CLEAR_STATIC_CONTENT,
56  'c',
57  InputOption::VALUE_NONE,
58  'Clear generated static view files. Necessary, if the module(s) have static view files'
59  );
60 
61  parent::configure();
62  }
63 
69  abstract protected function isModuleRequired();
70 
78  protected function cleanup(InputInterface $input, OutputInterface $output)
79  {
81  $cache = $this->objectManager->get(\Magento\Framework\App\Cache::class);
82  $cache->clean();
83  $output->writeln('<info>Cache cleared successfully.</info>');
85  $cleanupFiles = $this->objectManager->get(\Magento\Framework\App\State\CleanupFiles::class);
86  $cleanupFiles->clearCodeGeneratedClasses();
87  $output->writeln(
88  "<info>Generated classes cleared successfully. Please run the 'setup:di:compile' command to "
89  . 'generate classes.</info>'
90  );
91  if ($input->getOption(self::INPUT_KEY_CLEAR_STATIC_CONTENT)) {
92  $cleanupFiles->clearMaterializedViewFiles();
93  $output->writeln('<info>Generated static view files cleared successfully.</info>');
94  } else {
95  $output->writeln(
96  "<info>Info: Some modules might require static view files to be cleared. To do this, run '"
97  . $this->getName() . "' with the --" . self::INPUT_KEY_CLEAR_STATIC_CONTENT
98  . ' option to clear them.</info>'
99  );
100  }
101  }
102 }
cleanup($repo, $mainline)
__construct(ObjectManagerProvider $objectManagerProvider)