Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
WebsiteListCommand.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 WebsiteListCommand extends Command
20 {
24  private $manager;
25 
28  public function __construct(
29  \Magento\Store\Api\WebsiteRepositoryInterface $websiteManagement
30  ) {
31  $this->manager = $websiteManagement;
32  parent::__construct();
33  }
34 
38  protected function configure()
39  {
40  $this->setName('store:website:list')
41  ->setDescription('Displays the list of websites');
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', 'Default Group Id', 'Name', 'Code', 'Sort Order', 'Is Default']);
54 
55  foreach ($this->manager->getList() as $website) {
56  $table->addRow([
57  $website->getId(),
58  $website->getDefaultGroupId(),
59  $website->getName(),
60  $website->getCode(),
61  $website->getData('sort_order'),
62  $website->getData('is_default'),
63  ]);
64  }
65 
66  $table->render();
67 
68  return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
69  } catch (\Exception $e) {
70  $output->writeln('<error>' . $e->getMessage() . '</error>');
71  if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
72  $output->writeln($e->getTraceAsString());
73  }
74 
75  return \Magento\Framework\Console\Cli::RETURN_FAILURE;
76  }
77  }
78 }
__construct(\Magento\Store\Api\WebsiteRepositoryInterface $websiteManagement)
execute(InputInterface $input, OutputInterface $output)
$table
Definition: trigger.php:14