Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractDependenciesCommand.php
Go to the documentation of this file.
1 <?php
7 
15 use Symfony\Component\Console\Command\Command;
16 use Symfony\Component\Console\Input\InputOption;
17 use Symfony\Component\Console\Input\InputInterface;
18 use Symfony\Component\Console\Output\OutputInterface;
19 
23 abstract class AbstractDependenciesCommand extends Command
24 {
28  const INPUT_KEY_DIRECTORY = 'directory';
29 
33  const INPUT_KEY_OUTPUT = 'output';
34 
40  private $objectManager;
41 
47  public function __construct(ObjectManagerProvider $objectManagerProvider)
48  {
49  $this->objectManager = $objectManagerProvider->get();
50  parent::__construct();
51  }
52 
56  protected function configure()
57  {
58  $this->setDefinition(
59  [
60  new InputOption(
61  self::INPUT_KEY_OUTPUT,
62  'o',
63  InputOption::VALUE_REQUIRED,
64  'Report filename',
66  )
67  ]
68  );
69  parent::configure();
70  }
71 
78  abstract protected function buildReport($outputPath);
79 
85  abstract protected function getDefaultOutputFilename();
86 
90  protected function execute(InputInterface $input, OutputInterface $output)
91  {
92  try {
94  $componentRegistrar = $this->objectManager->get(\Magento\Framework\Component\ComponentRegistrar::class);
96  $dirSearch = $this->objectManager->get(\Magento\Framework\Component\DirSearch::class);
98  $themePackageList = $this->objectManager->get(\Magento\Framework\View\Design\Theme\ThemePackageList::class);
100  $this->buildReport($input->getOption(self::INPUT_KEY_OUTPUT));
101  $output->writeln('<info>Report successfully processed.</info>');
102  } catch (\Exception $e) {
103  $output->writeln(
104  '<error>Please check the path you provided. Dependencies report generator failed with error: ' .
105  $e->getMessage() . '</error>'
106  );
107  // we must have an exit code higher than zero to indicate something was wrong
108  return \Magento\Framework\Console\Cli::RETURN_FAILURE;
109  }
110  return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
111  }
112 }
$componentRegistrar
Definition: bootstrap.php:23
__construct(ObjectManagerProvider $objectManagerProvider)
$themePackageList
Definition: bootstrap.php:88
static setInstance(Files $instance=null)
Definition: Files.php:136
$dirSearch
Definition: bootstrap.php:86