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

Adding phpmig to app commands #75

Open
lalop opened this issue Jan 22, 2015 · 1 comment
Open

Adding phpmig to app commands #75

lalop opened this issue Jan 22, 2015 · 1 comment

Comments

@lalop
Copy link
Contributor

lalop commented Jan 22, 2015

I wanted to add phpmig to my app console entry point.
So I Wrote something like that :

use Phpmig\Console\Command;

$app = new Symfony\Component\Console\Application();

$phpmig_commands = [
    new Command\InitCommand(),
    new Command\StatusCommand(),
    new Command\CheckCommand(),
    new Command\GenerateCommand(),
    new Command\UpCommand(),
    new Command\DownCommand(),
    new Command\MigrateCommand(),
    new Command\RollbackCommand()
];
foreach($phpmig_commands as $command) {
    $command->setName('phpmig:'.$command->getName());
}

$app->addCommands($phpmig_commands);

$app->run();

That makes the job, but I've some issue with the configuration loading, maybe we can found a way to add phpmig commands to application commands and giving it the configuration by the same way.

For exemple :

use \Phpmig\Adapter,
    \Pimple;

$container = new Pimple();

$container['db'] = $container->share(function() {
    $dbh = new PDO('mysql:dbname=testdb;host=127.0.0.1','username','passwd');
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $dbh;
});

$container['phpmig.adapter'] = $container->share(function() use ($container) {
    return new Adapter\PDO\Sql($container['db'], 'migrations');
});

$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . 'migrations';
$container['phpmig.command_prefix']  = 'phpmig';

$app->addCommands(
\Phpmig\Console\PhpmigApplication::getCommands($container)
);
@ghost
Copy link

ghost commented Feb 10, 2015

+1 on this!
It would be nice to get ability to pass a container without configuration file.
As for Pimple based applications we have to register some services twice, and I think it could resolve this problem.

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

1 participant