Files
luos/workflow/engine/bin/rest-gen
Erik Amaru Ortiz de62be5506 Restful Feature, improvements on rest-gen cli command and Disptacher
On Dispatcher:
- Now it is handling Cross Domain AJAX request, it is accepting requests with method OPTIONS
- Now the behaviour of rest server is modified by confuguration
- The dispatcher can be load configuraion from a processmaker core dir. for all workspaces
and for a determinated workspace

On Cli Command:
- Now it can generate api crud for processmaker root dir and a determinated workspace
- More improvements to handle correctly build request for a plugin or a workspace or core of pmos
2012-08-30 16:26:19 -04:00

106 lines
3.4 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>
*/
$basePath = realpath(dirname(__FILE__) . '/../../../');
include $basePath . '/gulliver/core/Bootstrap.php';
include $basePath . '/workflow/engine/PmBootstrap.php';
$bootstrap = new PmBootstrap(array('path_trunk' => $basePath));
$bootstrap->registerClasses();
$bootstrap->configure();
if (! isset($argv[1])) {
$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;
echo $help;
exit(0);
}
$restTool = new Service_Rest_RestTool();
$restTool->setBasePath(PATH_CORE);
try {
switch ($argv[1]) {
case 'build-crud':
case 'gen-ini':
if (isset($argv[2])) {
if (! isset($argv[3])) {
throw new Exception("Missing option, need especify a valid argument after option '{$argv[2]}'");
}
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]));
}
}
$restTool->init();
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));
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) {
Service_Rest_RestTool::out($e->getMessage(), 'error');
}