If you are truly using a Single Command Application, you'll have to configure Doctrine on your own within the setCode()
method. E.g. following these instructions.
(new SingleCommandApplication())
->setName('My Super Command') // Optional
->setVersion('1.0.0') // Optional
->addArgument('foo', InputArgument::OPTIONAL, 'The directory')
->addOption('bar', null, InputOption::VALUE_REQUIRED)
->setCode(function (InputInterface $input, OutputInterface $output) {
$paths = array("/path/to/entity-files");
$isDevMode = false;
// the connection configuration
$dbParams = [
'driver' => 'pdo_mysql',
'user' => 'db_user',
'password' => 'very_secret',
'dbname' => 'foo',
];
$config = Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$em = Doctrine\ORM\EntityManager::create($dbParams, $config);
// output arguments and options
})
->run();
On a single command application you do not have "bundles" as such, since you are operating outside of the Framework bundle, and generally you wouldn't have access to dependency injection either.
(If you wanted DI, you'd probably have something like this while calling the setDefaultCommand()
method on the instantiated Application
object, but you'd still need to instantiate the Doctrine connection "manually", even if you are doing on a different service to be injected).