2012-08-23 13:01:19 -04:00
|
|
|
#!/usr/bin/env php
|
2012-08-20 18:33:25 -04:00
|
|
|
<?php
|
2012-08-27 10:48:32 -04:00
|
|
|
/**
|
|
|
|
|
* 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>
|
|
|
|
|
*/
|
|
|
|
|
|
2012-08-30 16:26:19 -04:00
|
|
|
$basePath = realpath(dirname(__FILE__) . '/../../../');
|
|
|
|
|
include $basePath . '/gulliver/core/Bootstrap.php';
|
|
|
|
|
include $basePath . '/workflow/engine/PmBootstrap.php';
|
2012-08-20 18:33:25 -04:00
|
|
|
|
2012-08-30 16:26:19 -04:00
|
|
|
$bootstrap = new PmBootstrap(array('path_trunk' => $basePath));
|
2012-08-20 18:33:25 -04:00
|
|
|
$bootstrap->registerClasses();
|
|
|
|
|
$bootstrap->configure();
|
|
|
|
|
|
|
|
|
|
if (! isset($argv[1])) {
|
2012-08-30 16:26:19 -04:00
|
|
|
$help = <<<EOT
|
|
|
|
|
Usage: {$argv[0]} [build-crud] [gen-ini] [-p <plugin name>] [-w <workspace name>]
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
build-crud : Task, build Rest Crud API.
|
|
|
|
|
gen-ini : Task, generates the rest config ini file.
|
|
|
|
|
-p : Especify a plugin to set as enviroment to perform the tasks.
|
|
|
|
|
-w : Especify a workspace to set as enviroment to perform the tasks.
|
|
|
|
|
|
|
|
|
|
EOT;
|
2012-08-20 18:33:25 -04:00
|
|
|
|
|
|
|
|
echo $help;
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$restTool = new Service_Rest_RestTool();
|
2012-08-30 16:26:19 -04:00
|
|
|
$restTool->setBasePath(PATH_CORE);
|
2012-08-20 18:33:25 -04:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
switch ($argv[1]) {
|
2012-08-30 16:26:19 -04:00
|
|
|
case 'build-crud':
|
|
|
|
|
case 'gen-ini':
|
2012-08-27 10:48:32 -04:00
|
|
|
if (isset($argv[2])) {
|
2012-08-30 16:26:19 -04:00
|
|
|
if (! isset($argv[3])) {
|
|
|
|
|
throw new Exception("Missing option, need especify a valid argument after option '{$argv[2]}'");
|
2012-08-27 10:48:32 -04:00
|
|
|
}
|
|
|
|
|
|
2012-08-30 16:26:19 -04:00
|
|
|
switch ($argv[2]) {
|
|
|
|
|
case '-p':
|
|
|
|
|
// attempt create rest api from a plugin
|
|
|
|
|
if (! is_dir(PATH_PLUGINS . $argv[3])) {
|
|
|
|
|
throw new Exception(sprintf("Plugin '%s' doesn't exist.", $argv[3]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$restTool->setBasePath($optPath = PATH_PLUGINS . $argv[3] . PATH_SEP);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '-w':
|
|
|
|
|
// attempt create rest api from a plugin
|
|
|
|
|
if (! is_dir(PATH_DATA . 'sites' . PATH_SEP . $argv[3])) {
|
|
|
|
|
throw new Exception(sprintf("Workspace '%s' doesn't exist.", $argv[3]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$path = PATH_DATA . 'sites' . PATH_SEP . $argv[3] . PATH_SEP;
|
|
|
|
|
$restTool->setBasePath($path);
|
|
|
|
|
$restTool->setConfigFile($path . 'rest-config.ini');
|
|
|
|
|
$restTool->setDbXmlSchemaFile(PATH_CONFIG . 'schema.xml');
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Exception(sprintf("Invalid option '%s'", $argv[2]));
|
|
|
|
|
}
|
2012-08-27 10:48:32 -04:00
|
|
|
}
|
|
|
|
|
|
2012-08-30 16:26:19 -04:00
|
|
|
$restTool->init();
|
2012-08-20 18:33:25 -04:00
|
|
|
|
2012-08-30 16:26:19 -04:00
|
|
|
if ($argv[1] == 'build-crud') {
|
|
|
|
|
$restTool->buildCrudApi();
|
|
|
|
|
} else {
|
|
|
|
|
if (file_exists(PATH_CONFIG . '/rest-config.ini')) {
|
|
|
|
|
echo "The file 'rest-config.ini' already exits, overwrite (Y/n)? ";
|
|
|
|
|
$resp = trim(fgets(STDIN));
|
2012-08-20 18:33:25 -04:00
|
|
|
|
2012-08-30 16:26:19 -04:00
|
|
|
if (strtolower($resp) != 'y') {
|
|
|
|
|
echo "Skipped\n";
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
2012-08-20 18:33:25 -04:00
|
|
|
}
|
|
|
|
|
|
2012-08-30 16:26:19 -04:00
|
|
|
echo "Generating config ini file ... ";
|
2012-08-20 18:33:25 -04:00
|
|
|
|
2012-08-30 16:26:19 -04:00
|
|
|
$genFile = $restTool->buildConfigIni();
|
2012-08-20 18:33:25 -04:00
|
|
|
|
2012-08-30 16:26:19 -04:00
|
|
|
echo "DONE!\n";
|
|
|
|
|
echo "File generated: $genFile\n\n";
|
|
|
|
|
}
|
2012-08-20 18:33:25 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
echo "Invalid option!\n";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
2012-08-30 16:26:19 -04:00
|
|
|
Service_Rest_RestTool::out($e->getMessage(), 'error');
|
2012-08-20 18:33:25 -04:00
|
|
|
}
|