diff --git a/composer.json b/composer.json index 938f095ea..092505818 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,6 @@ "license": "GNU Affero General Public License version 3", "require": { - "luracast/restler" : "3.0.0" + "luracast/restler" : "dev-master" } } \ No newline at end of file diff --git a/gulliver/system/class.bootstrap.php b/gulliver/system/class.bootstrap.php index 9cf874831..3d51d2810 100644 --- a/gulliver/system/class.bootstrap.php +++ b/gulliver/system/class.bootstrap.php @@ -1059,17 +1059,57 @@ class Bootstrap } return $res; } - + //use Luracast\Restler\Format\XmlFormat as XmlFormat; /** - * This method allow dispatch rest services using 'Restler' thirdparty library + * This method dispatch rest/api services + * it implement "Restler" library * + * @param $url string Contains the url request * @author Erik Amaru Ortiz */ - public function dispatchRestService($uri, $config, $apiClassesPath = '') + public function dispatchApiService($uri, $config, $apiClassesPath = '') { - require_once 'restler/restler.php'; + $rest = new Luracast\Restler\Restler(); + + $dataUri = explode('/', $uri); + array_shift($dataUri); + $reqClass = ucfirst(array_shift($dataUri)); + $servicesDir = PATH_CORE . 'services' . PATH_SEP; + $apiDir = $servicesDir . 'api' . PATH_SEP; + $namespace = 'Services_Api_'; + $classFile = $apiDir . $namespace . $reqClass . '.php'; + + if (! file_exists($classFile)) { + //throw new Luracast\Restler\RestException(404, "Invalid Service Request"); + $rest->handleError(404); + die; + } + + require_once $classFile; + + $_SERVER['REQUEST_URI'] = $uri; + + $rest->setSupportedFormats('JsonFormat', 'XmlFormat'); + $rest->addAPIClass($namespace . $reqClass); + $rest->handle(); + die; + + + + + + + + + + + + + + + + // OLD CODE FROM HERE - $rest = new Restler(); $rest->setSupportedFormats('JsonFormat', 'XmlFormat'); // getting all services class $restClasses = array(); @@ -2275,18 +2315,36 @@ class Bootstrap } /** + * This function parse a particular api/rest request * - * @param unknown_type $requestUri + * Example url: + * GET /api/workflowdemo/user/rol?id=0000000000000000001 + * POST /api/workflowdemo/cases + * + * - These urls are equivalents + * GET /api//cases/start + * GET /-api/cases/start + * + * @param $url + * @return array return url parsed data */ - public function parseRestUri($requestUri) + public function parseRestUri($url) { + array_shift($url); + $sysTemp = array_shift($url); + + if ($sysTemp == 'api') { + $sysTemp = array_shift($url); + } elseif (strpos($sysTemp, '-') !== false) { + list($sysTemp,) = explode('-', $sysTemp); + } + $args = array(); - //$args['SYS_TEMP'] = $requestUri[1]; - define('SYS_TEMP', $requestUri[2]); + define('SYS_TEMP', $sysTemp); $restUri = ''; - for ($i = 3; $i < count($requestUri); $i++) { - $restUri .= '/' . $requestUri[$i]; + foreach ($url as $urlPart) { + $restUri .= '/' . $urlPart; } $args['SYS_LANG'] = 'en'; // TODO, this can be set from http header @@ -3016,5 +3074,27 @@ class Bootstrap { return strtoupper(PHP_OS) == "LINUX"; } + + public static function initVendors() + { + if (! is_dir(PATH_TRUNK . 'vendor')) { + if (file_exists(PATH_TRUNK . 'composer.phar')) { + throw new Exception( + "ERROR: Verdors are missing!\n" . + "Please execute the following command to install vendors for the environment:\n" . + "$>php composer.phar install" + ); + } else { + throw new Exception( + "ERROR: Verdors are missing!\n" . + "Please execute the following commands to prepare/install vendors for the environment:\n" . + "$>curl -sS https://getcomposer.org/installer | php\n" . + "$>php composer.phar install" + ); + } + } + + require_once PATH_TRUNK . 'vendor' . PATH_SEP . "autoload.php"; + } } diff --git a/workflow/engine/services/api/Services_Api_Say.php b/workflow/engine/services/api/Services_Api_Say.php new file mode 100644 index 000000000..8b9b04a33 --- /dev/null +++ b/workflow/engine/services/api/Services_Api_Say.php @@ -0,0 +1,21 @@ +true, "message"=>"Hello $to!"); + } + + public function hi($to, $name) + { + return "Hi $to -> $name"; + } +} \ No newline at end of file diff --git a/workflow/public_html/sysGeneric.php b/workflow/public_html/sysGeneric.php index 4f5f50af4..f3124abe0 100755 --- a/workflow/public_html/sysGeneric.php +++ b/workflow/public_html/sysGeneric.php @@ -236,6 +236,8 @@ set_include_path( PATH_CORE . PATH_SEPARATOR . get_include_path() ); +Bootstrap::initVendors(); + /** * Global definitions, before it was the defines.php file */ @@ -351,7 +353,7 @@ $virtualURITable['/html2ps_pdf/(*)'] = PATH_THIRDPARTY . 'html2ps_pdf/'; //$virtualURITable['/images/'] = 'errorFile'; //$virtualURITable['/skins/'] = 'errorFile'; //$virtualURITable['/files/'] = 'errorFile'; -$virtualURITable['/rest/(*)'] = 'rest-service'; +$virtualURITable['/(*)api/(*)'] = 'api-service'; $virtualURITable["/update/(*)"] = ($skinPathUpdate != "")? $skinPathUpdate : PATH_GULLIVER_HOME . "methods" . PATH_SEP . "update" . PATH_SEP; //$virtualURITable['/(*)'] = PATH_HTML; $virtualURITable['/css/(*)'] = PATH_HTML . 'css/'; //ugly @@ -438,7 +440,7 @@ if (Bootstrap::virtualURI( $_SERVER['REQUEST_URI'], $virtualURITable, $realPath break; default: //Process files loaded with tag head in HTML - if (substr( $realPath, 0, 12 ) == 'rest-service') { + if (substr( $realPath, 0, 11 ) == 'api-service') { $isRestRequest = true; } else { $realPath = explode( '?', $realPath ); @@ -635,7 +637,7 @@ Bootstrap::LoadClass( 'memcached' ); $memcache = & PMmemcached::getSingleton( SYS_SYS ); // verify configuration for rest service -if ($isRestRequest) { +/*if ($isRestRequest) { // disable until confirm that rest is enabled & configured on rest-config.ini file $isRestRequest = false; $confFile = ''; @@ -655,7 +657,7 @@ if ($isRestRequest) { } } } -} +}*/ // load Plugins base class Bootstrap::LoadClass( 'plugin' ); @@ -1002,9 +1004,10 @@ if (! defined( 'EXECUTE_BY_CRON' )) { $controller->call($controllerAction); } elseif ($isRestRequest) { + $restConfig = array(); //NewRelic Snippet - By JHL - transactionLog($restConfig.$restApiClassPath.SYS_TARGET); - Bootstrap::dispatchRestService( SYS_TARGET, $restConfig, $restApiClassPath ); + //transactionLog($restConfig.PATH_DATA_SITE.SYS_TARGET); // ====> ??? this concat is very rare + Bootstrap::dispatchApiService(SYS_TARGET, $restConfig, PATH_DATA_SITE); } else { //NewRelic Snippet - By JHL transactionLog($phpFile);