Altax\Command\Builtin\RolesCommand::execute PHP Метод

execute() защищенный Метод

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $container = $this->getApplication()->getContainer();
        $roles = $container->get('roles');
        $format = $input->getOption('format');
        if ('txt' === $format) {
            if ($roles) {
                $table = $this->getHelperSet()->get('table');
                $table->setHeaders(array('name', 'nodes'));
                foreach ($roles as $key => $nodes) {
                    $table->addRow(array($key, trim(implode(', ', $nodes))));
                }
                $table->render($output);
            } else {
                $output->writeln('There are not any roles.');
            }
        } else {
            if ('json' === $format) {
                $data = array();
                if ($roles) {
                    foreach ($roles as $key => $nodes) {
                        $data[$key] = array('nodes' => $nodes);
                    }
                }
                $output->writeln(json_encode($data));
            } else {
                throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $format));
            }
        }
    }