-
-
Save lotfio/8e5ecd46e7ea97440e2a23fe63db5fbb to your computer and use it in GitHub Desktop.
phinx outside cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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