function printUsage($error = null) { echo "PoC Migration tool (ivasilchev) \n"; echo $error; echo "Usage : migrate < up | down > <migration name> \n"; echo "Example: migrate up special-days \n"; echo "\n"; exit; } if ($argc < 3) { printUsage("Not enough paramteres"); } if (in_array($argv[1], ['up', 'down']) == false) { echo "------{$argv[2]}-----"; printUsage("Error: Invalid parameter - migration step must be 'up' or 'down'"); } if (in_array($argv[2], array_keys($aliases)) == false) { printUsage("Error: Unknown migration alias " . $argv[3] . "\n" . "Available migrations: " . implode(',', array_keys($aliases))); } $migration = new $aliases[$argv[2]]['class'](); $executor = new Executor(include_once 'dbconfig.php'); switch ($argv[1]) { case 'up': $executor->executeUp($migration); break; case 'down': $executor->executeDown($migration); break; default: exit('Unexpected input for migration type :' . $argv[1]); }