78 lines
2.1 KiB
PHP
Executable File
78 lines
2.1 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
/**
|
|
* rest-gen bin command
|
|
*
|
|
* This file uses Service_Rest_RestTool class to generate a rest-config.ini file
|
|
* and build rest crud api for 'Restler' lib.
|
|
*
|
|
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com>
|
|
*/
|
|
|
|
include dirname(__FILE__) . '/../../../gulliver/core/Bootstrap.php';
|
|
include dirname(__FILE__) . '/../../../workflow/engine/PmBootstrap.php';
|
|
|
|
$config = array(
|
|
'path_trunk' => realpath(dirname(__FILE__) . '/../../../')
|
|
);
|
|
|
|
$bootstrap = new PmBootstrap($config);
|
|
$bootstrap->registerClasses();
|
|
$bootstrap->configure();
|
|
|
|
if (! isset($argv[1])) {
|
|
$help = '$>' . $argv[0] . " [option] [plugin-name]\n";
|
|
$help .= "Avalaibles options:\n";
|
|
$help .= " build-api : Build Crud Rest API from ProcessMaker or a plugin.\n";
|
|
$help .= " gen-ini : Generates the rest config ini file.\n";
|
|
$help .= "* [plugin-name] : (Optional) to specify create crud api for a determiated plugin.\n\n";
|
|
|
|
echo $help;
|
|
exit(0);
|
|
}
|
|
|
|
$restTool = new Service_Rest_RestTool();
|
|
|
|
try {
|
|
switch ($argv[1]) {
|
|
case 'build-api':
|
|
if (isset($argv[2])) {
|
|
// attemp create rest api from a plugin
|
|
if (! is_dir(PATH_PLUGINS . $argv[2])) {
|
|
throw new Exception(sprintf("Plugin '%s' doesn't exist.", $argv[2]));
|
|
}
|
|
|
|
$restTool->setBasePath(PATH_PLUGINS . $argv[2] . PATH_SEP);
|
|
}
|
|
|
|
$restTool->buildApi();
|
|
break;
|
|
|
|
case 'gen-ini':
|
|
if (file_exists(PATH_CONFIG . '/rest-config.ini')) {
|
|
echo "The file 'rest-config.ini' already exits, overwrite (Y/n)? ";
|
|
$resp = trim(fgets(STDIN));
|
|
|
|
if (strtolower($resp) != 'y') {
|
|
echo "Skipped\n";
|
|
exit(0);
|
|
}
|
|
}
|
|
|
|
echo "Generating config ini file ... ";
|
|
|
|
$genFile = $restTool->buildConfigIni();
|
|
|
|
echo "DONE!\n";
|
|
echo "File generated: $genFile\n\n";
|
|
|
|
break;
|
|
|
|
default:
|
|
echo "Invalid option!\n";
|
|
break;
|
|
}
|
|
} catch (Exception $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|