Skip to content

Instantly share code, notes, and snippets.

@mikaelz
Last active May 18, 2017 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelz/1e10ae52b62f6da381faf51c4b4d2a23 to your computer and use it in GitHub Desktop.
Save mikaelz/1e10ae52b62f6da381faf51c4b4d2a23 to your computer and use it in GitHub Desktop.
Phinx usage in Symfony2 controller without CLI. Result at https://michalzuber.wordpress.com/2017/05/18/phinx-migrate-in-php-without-cli/
<?php
use Phinx\Console\PhinxApplication;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpFoundation\Response;
public function migrateDbAction()
{
$kernel = $this->get('kernel');
$phinx = new PhinxApplication();
$phinx->setAutoExit(false);
$input = new ArrayInput(array(
'command' => 'migrate',
'-c' => dirname($kernel->getRootDir()).'/phinx.yml',
'-e' => $kernel->getEnvironment(),
));
$output = new BufferedOutput();
$phinx->run($input, $output);
return new Response(nl2br($output->fetch()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment