src/Silex/Doctrine/DBAL/Tools/Console/Command/DropDatabaseCommand.php
protected function execute( InputInterface $input, OutputInterface $output )
    {
        parent::execute($input, $output);

        $params = $this->getConnectionParams($input->getOption('connection'));

        $databaseName = isset($params['path']) && $params['driver'] == 'pdo_sqlite' ?
            $params['path'] : $params['dbname'];

        if (!$databaseName) {
            throw new \InvalidArgumentException(
                'Connection does not contain a \'path\' or \'dbname\' '.
                'parameter and cannot be dropped.'
            );
        }

        if ($input->getOption('force')) {
            // Only quote if we don't have a path
            if ($params['driver'] != 'pdo_sqlite') {
                $databaseName = $this->getConnection()
                    ->getDatabasePlatform()->quoteSingleIdentifier($databaseName);
            }

            try {
                $this->getConnection()->getSchemaManager()
                    ->dropDatabase($databaseName);
                $output->writeln(
                    sprintf(
                        '<info>Dropped database <comment>%s</comment> ' .
                        'for connection <comment>%s</comment></info>',
                        $databaseName, $input->getOption('connection')
                    )
                );
            } catch (\Exception $e) {
                $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
                $output->writeln(
                    sprintf(
                        '<error>Could not drop database <comment>%s</comment> ' .
                        'for connection <comment>%s</comment></error>',
                        $databaseName
                    )
                );
                throw $e;
            }
        } else {
            $output->writeln(
                '<error>Attention:</error> This operation should not be executed ' .
                'in a production environment.'
            );
            $output->writeln('');
            $output->writeln(
                sprintf(
                    '<info>Would drop the database named ' .
                    '<comment>%s</comment>.</info>', $databaseName
                )
            );
            $output->writeln('Please run the operation with --force to execute');
            $output->writeln('<error>All data will be lost!</error>');
        }

        $this->getConnection()->close();
    }
protected function execute( InputInterface $input, OutputInterface $output )
    {
        parent::execute($input, $output);

        $params = $this->getConnectionParams($input->getOption('connection'));

        $databaseName = isset($params['path']) && $params['driver'] == 'pdo_sqlite' ?
            $params['path'] : $params['dbname'];

        if (!$databaseName) {
            throw new \InvalidArgumentException(
                'Connection does not contain a \'path\' or \'dbname\' '.
                'parameter and cannot be dropped.'
            );
        }

        if ($input->getOption('force')) {
            // Only quote if we don't have a path
            if ($params['driver'] != 'pdo_sqlite') {
                $databaseName = $this->getConnection()
                    ->getDatabasePlatform()->quoteSingleIdentifier($databaseName);
            }

            try {
                $this->getConnection()->getSchemaManager()
                    ->dropDatabase($databaseName);
                $output->writeln(
                    sprintf(
                        '<info>Dropped database <comment>%s</comment> ' .
                        'for connection <comment>%s</comment></info>',
                        $databaseName, $input->getOption('connection')
                    )
                );
            } catch (\Exception $e) {
                $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
                $output->writeln(
                    sprintf(
                        '<error>Could not drop database <comment>%s</comment> ' .
                        'for connection <comment>%s</comment></error>',
                        $databaseName
                    )
                );
                throw $e;
            }
        } else {
            $output->writeln(
                '<error>Attention:</error> This operation should not be executed ' .
                'in a production environment.'
            );
            $output->writeln('');
            $output->writeln(
                sprintf(
                    '<info>Would drop the database named ' .
                    '<comment>%s</comment>.</info>', $databaseName
                )
            );
            $output->writeln('Please run the operation with --force to execute');
            $output->writeln('<error>All data will be lost!</error>');
        }

        $this->getConnection()->close();
    }
Executes command

@param InputInterface  $input  Command input
@param OutputInterface $output Console output

@throws \Exception

@return void