dflydev / dflydev-doctrine-orm-service-provider

Doctrine ORM Service Provider
MIT License
209 stars 59 forks source link

Question: Adding the Doctorine CLI to Silex Console App #11

Open bassettsj opened 11 years ago

bassettsj commented 11 years ago

First of all thanks for putting this out there @dflydev. I am lost as to adding the Doctrine CLI functions to my applications console to be able to create the Doctrine schema. I am using lyrixx/Silex-Kitchen-Edition to structure the application. They have already included a nice symfony/Console component, so my question is how I can integration the Doctrine ORM Service provider there to be able to handle generating the entity tabels.

dominikzogg commented 11 years ago

@bassettsj 12-17: https://github.com/dominikzogg/silexskeleton/blob/master/app/console#L12

I uses my manager registry (https://github.com/dominikzogg/doctrine-orm-manager-registry-provider), without you need to replace $app['doctrine']->getConnection() with $app['db'] and $app['doctrine']->getManager() with $app['em']

arsfeld commented 11 years ago

I used Silex Kitchen Edition as well and added the following to src/console.php:

$em = $app['orm.em'];

$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));

$console->setHelperSet($helperSet);

$console->addCommands(array(
    // DBAL Commands
    new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(),
    new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(),

    // ORM Commands
    new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(),
    new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(),
    new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(),
    new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(),
    new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(),
    new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(),
    new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(),
    new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(),
    new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(),
    new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(),
    new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(),
    new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(),
    new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(),
    new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(),

));

Works like a charm!

marcojanssen commented 11 years ago

Take a look @ https://github.com/marcojanssen/silex-rest

in app/console.php i added:

/*
 * Doctrine CLI
 */
$helperSet = new HelperSet(array(
    'db' => new ConnectionHelper($app['orm.em']->getConnection()),
    'em' => new EntityManagerHelper($app['orm.em'])
));

$console->setHelperSet($helperSet);
Doctrine\ORM\Tools\Console\ConsoleRunner::addCommands($console);
dominikzogg commented 10 years ago

https://github.com/saxulum/saxulum-doctrine-orm-manager-registry-provider

this way you get fully wupport for all entity managers (if there are many)

erikaheidi commented 10 years ago

Thanks @marcojanssen, clean solution worked perfectly :+1:

dominikzogg commented 10 years ago

@erikaheidi this is probably the most poerfull way in silex atm: https://github.com/saxulum/saxulum-doctrine-orm-manager-registry-provider#doctrine-orm-console