Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StoreListCommand.php
Go to the documentation of this file.
1 <?php
8 
9 use Symfony\Component\Console\Helper\Table;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 
19 class StoreListCommand extends Command
20 {
24  private $storeManager;
25 
28  public function __construct(
29  \Magento\Store\Model\StoreManagerInterface $storeManager
30  ) {
31  $this->storeManager = $storeManager;
32  parent::__construct();
33  }
34 
38  protected function configure()
39  {
40  $this->setName('store:list')
41  ->setDescription('Displays the list of stores');
42 
43  parent::configure();
44  }
45 
49  protected function execute(InputInterface $input, OutputInterface $output)
50  {
51  try {
52  $table = new Table($output);
53  $table->setHeaders(['ID', 'Website ID', 'Group ID', 'Name', 'Code', 'Sort Order', 'Is Active']);
54 
55  foreach ($this->storeManager->getStores(true, true) as $store) {
56  $table->addRow([
57  $store->getId(),
58  $store->getWebsiteId(),
59  $store->getStoreGroupId(),
60  $store->getName(),
61  $store->getCode(),
62  $store->getData('sort_order'),
63  $store->getData('is_active'),
64  ]);
65  }
66 
67  $table->render();
68 
69  return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
70  } catch (\Exception $e) {
71  $output->writeln('<error>' . $e->getMessage() . '</error>');
72  if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
73  $output->writeln($e->getTraceAsString());
74  }
75 
76  return \Magento\Framework\Console\Cli::RETURN_FAILURE;
77  }
78  }
79 }
$storeManager
__construct(\Magento\Store\Model\StoreManagerInterface $storeManager)
execute(InputInterface $input, OutputInterface $output)
$table
Definition: trigger.php:14