UPDATE, Update Restler implementation ver 3.0
- First Funcional Commit to implement Restler 3.0
- PM supports now urls requests like:
GET /api/<workspace_name>/class_name/method?param1=value1
example:
GET /api/workflow/class_name/mothod?param1=value1
There is an equivalent expresion for url above
GET /<workspace_name>-api/class_name/mothod?param1=value1
example:
GET /workflow-api/class_name/mothod?param1=value1
* and all route expressions that Restler supports
This commit is contained in:
@@ -6,6 +6,6 @@
|
||||
"license": "GNU Affero General Public License version 3",
|
||||
|
||||
"require": {
|
||||
"luracast/restler" : "3.0.0"
|
||||
"luracast/restler" : "dev-master"
|
||||
}
|
||||
}
|
||||
@@ -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 <aortiz.erik@gmail.com>
|
||||
*/
|
||||
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/<workspaceName>/cases/start
|
||||
* GET /<workspaceName>-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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
workflow/engine/services/api/Services_Api_Say.php
Normal file
21
workflow/engine/services/api/Services_Api_Say.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: erik
|
||||
* Date: 8/21/13
|
||||
* Time: 4:55 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
class Services_Api_Say
|
||||
{
|
||||
public function hello($to='world')
|
||||
{
|
||||
return array('success'=>true, "message"=>"Hello $to!");
|
||||
}
|
||||
|
||||
public function hi($to, $name)
|
||||
{
|
||||
return "Hi $to -> $name";
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user