database = $database; parent::__construct(); } /** * {@inheritdoc} */ protected function configure() { $this ->setName('debug:database:table') ->setDescription($this->trans('commands.debug.database.table.description')) ->addOption( 'database', null, InputOption::VALUE_OPTIONAL, $this->trans('commands.debug.database.table.options.database'), 'default' ) ->addArgument( 'table', InputArgument::OPTIONAL, $this->trans('commands.debug.database.table.arguments.table'), null ) ->setHelp($this->trans('commands.debug.database.table.help')) ->setAliases(['ddt']); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $database = $input->getOption('database'); $table = $input->getArgument('table'); $databaseConnection = $this->resolveConnection($database); if ($table) { $result = $this->database ->query('DESCRIBE '. $table .';') ->fetchAll(); if (!$result) { throw new \Exception( sprintf( $this->trans('commands.debug.database.table.messages.no-connection'), $database ) ); } $tableHeader = [ $this->trans('commands.debug.database.table.messages.column'), $this->trans('commands.debug.database.table.messages.type') ]; $tableRows = []; foreach ($result as $record) { $column = json_decode(json_encode($record), true); $tableRows[] = [ 'column' => $column['Field'], 'type' => $column['Type'], ]; } $this->getIo()->table($tableHeader, $tableRows); return 0; } $schema = $this->database->schema(); $tables = $schema->findTables('%'); $this->getIo()->comment( sprintf( $this->trans('commands.debug.database.table.messages.table-show'), $databaseConnection['database'] ) ); $this->getIo()->table( [$this->trans('commands.debug.database.table.messages.table')], $tables ); return 0; } }