Skip to content

Instantly share code, notes, and snippets.

@lotfio
Forked from jmny/migration.php
Last active December 11, 2019 10:09
Show Gist options
  • Save lotfio/8e5ecd46e7ea97440e2a23fe63db5fbb to your computer and use it in GitHub Desktop.
Save lotfio/8e5ecd46e7ea97440e2a23fe63db5fbb to your computer and use it in GitHub Desktop.
phinx outside cli
$phinxApp = new \Phinx\Console\PhinxApplication();
$phinxTextWrapper = new \Phinx\Wrapper\TextWrapper($phinxApp);
$phinxTextWrapper->setOption('configuration', 'phinx.yml');
$phinxTextWrapper->setOption('parser', 'YAML');
$phinxTextWrapper->setOption('environment', 'development');
$output = $phinxTextWrapper->getMigrate();
$output = explode("\n", $output);
// clean extra output
$out = array_values(array_filter(array_map(function($elem){
return preg_match('/(All\sDone.)|(==.*)|(PDOException)/', $elem) ? $elem : NULL;
}, $output)));
$response = array();
foreach($out as $index => $line)
{
if(strpos($line, 'PDOException') !== FALSE)
{
$response['status'] = "Error";
$response['code'] = 1;
$response['message'] = $line;
unset($output[$index]);
}elseif(strpos($line, 'All Done.') !== FALSE){
$response['status'] = "Success";
$response['code'] = 0;
$response['message'] = $line;
unset($output[$index]);
}else{
$response["data"][] = ltrim($line,"== ");
}
}
print_r(json_encode($response));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment