Exemplo n.º 1
0
        }
        $progress->finish();
        $output->writeln($container->getParameter('parameter.example'));
    }
}
class DatabaseCommand extends ContainerAwareCommand
{
    use ContainerInjector;
    protected function configure()
    {
        $this->setName('database');
        $this->setDescription('* Exemple with database');
    }
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (!class_exists('Doctrine\\DBAL\\Connection')) {
            $output->write('You need to include "doctrine/dbal" package in your composer.json');
            return false;
        }
        $databaseTables = $this->getContainer()->get('database.connection')->query('SHOW TABLES')->fetchAll();
        $tableHelper = $this->getHelper('table');
        $tableHelper->setHeaders(['Table name']);
        $tableHelper->setRows($databaseTables);
        $tableHelper->render($output);
    }
}
$application = new Application('Application name', 'Version', new ContainerConfig(__DIR__ . '/services.xml'));
$application->add(new ExampleCommand());
$application->add(new DatabaseCommand());
$application->run();