Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bassettsj opened this issue Jun 20, 2013 · 6 comments
Open

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

bassettsj opened this issue Jun 20, 2013 · 6 comments

Comments

@bassettsj
Copy link

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
Copy link
Contributor

@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
Copy link
Contributor

arsfeld commented Aug 23, 2013

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link

Thanks @marcojanssen, clean solution worked perfectly 👍

@dominikzogg
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants