Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InfoCurrencyListCommand.php
Go to the documentation of this file.
1 <?php
8 
9 use Symfony\Component\Console\Helper\TableFactory;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
15 
19 class InfoCurrencyListCommand extends Command
20 {
26  private $lists;
27 
31  private $tableHelperFactory;
32 
37  public function __construct(Lists $lists, TableFactory $tableHelperFactory = null)
38  {
39  $this->lists = $lists;
40  $this->tableHelperFactory = $tableHelperFactory ?: ObjectManager::getInstance()->create(TableFactory::class);
41  parent::__construct();
42  }
43 
47  protected function configure()
48  {
49  $this->setName('info:currency:list')
50  ->setDescription('Displays the list of available currencies');
51 
52  parent::configure();
53  }
54 
58  protected function execute(InputInterface $input, OutputInterface $output)
59  {
60  $tableHelper = $this->tableHelperFactory->create(['output' => $output]);
61  $tableHelper->setHeaders(['Currency', 'Code']);
62 
63  foreach ($this->lists->getCurrencyList() as $key => $currency) {
64  $tableHelper->addRow([$currency, $key]);
65  }
66 
67  $tableHelper->render();
68  return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
69  }
70 }
execute(InputInterface $input, OutputInterface $output)
__construct(Lists $lists, TableFactory $tableHelperFactory=null)