I want to store database connections in a static database. On demand I want to create a new database, store the credentials in my static database and then create the schema inside the new database from existing entities. I know how to do that by using symfony's command line tool. My goal is to make it work in a service. I looked into the Doctrine docs and try to make something work:
$conn =$this->getDoctrine()->getConnection()->getSchemaManager()->createDatabase($dbname);
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array('UiCoreDbBundle/Entity'), $isDevMode);
$conn = array(
'driver' => 'pdo_mysql',
'host' => '127.0.0.1',
'user' => 'root',
'dbname' => $dbname
);
$em = EntityManager::create($conn,$config);
$tool = new SchemaTool($em);
$classes = array(
$em->getClassMetadata('Product')
//...
);
$tool->createSchema($classes);
My example code does not work like i hoped it would. Doctrine can't find my entities. Can anyone give me a hint on the proper way to implement such a task?