From 3390653b505a5d01c14aa531135b818178afcc5d Mon Sep 17 00:00:00 2001 From: Erik Amaru Ortiz Date: Thu, 30 Aug 2012 17:35:39 -0400 Subject: [PATCH] Restful feature, adding merge of class files to expose betwwen a workspace and core classes - Now when a workspace was configured for rest service both classes on workspace and core will be exposed merging all classes with precedence of workspace classes --- gulliver/system/class.g.php | 42 +++++++++++++++++++------- workflow/engine/services/rest/Case.php | 18 +---------- workflow/public_html/sysGeneric.php | 5 +-- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index 3e889b8b1..df707048e 100755 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -5169,7 +5169,7 @@ function getDirectorySize($path,$maxmtime=0) * * @author Erik Amaru Ortiz */ - public function dispatchRestService($uri, $config = array()) + public function dispatchRestService($uri, $config, $apiClassesPath = '') { require_once 'restler/restler.php'; @@ -5177,18 +5177,38 @@ function getDirectorySize($path,$maxmtime=0) $rest->setSupportedFormats('JsonFormat', 'XmlFormat'); // getting all services class - $srvClasses = glob(PATH_SERVICES_REST . '*.php'); - $crudClasses = glob(PATH_SERVICES_REST . 'crud/*.php'); - $srvClasses = array_merge($srvClasses, $crudClasses); - - // hook to get rest api classes from plugins - if ( class_exists( 'PMPluginRegistry' ) ) { - $pluginRegistry = & PMPluginRegistry::getSingleton(); - $pluginClasses = $pluginRegistry->getRegisteredRestClassFiles(); - $srvClasses = array_merge($srvClasses, $pluginClasses); + $restClasses = array(); + $restClassesList = G::rglob('*', 0, PATH_CORE . 'services/'); + foreach ($restClassesList as $classFile) { + if (substr($classFile, -4) === '.php') { + $restClasses[str_replace('.php', '', basename($classFile))] = $classFile; + } } - foreach ($srvClasses as $classFile) { + if (! empty($apiClassesPath)) { + $pluginRestClasses = array(); + $restClassesList = G::rglob('*', 0, $apiClassesPath . 'services/'); + foreach ($restClassesList as $classFile) { + if (substr($classFile, -4) === '.php') { + $pluginRestClasses[str_replace('.php', '', basename($classFile))] = $classFile; + } + } + $restClasses = array_merge($restClasses, $pluginRestClasses); + } + + + // hook to get rest api classes from plugins + if (class_exists('PMPluginRegistry')) { + $pluginRegistry = & PMPluginRegistry::getSingleton(); + $pluginClasses = $pluginRegistry->getRegisteredRestClassFiles(); + $restClasses = array_merge($restClasses, $pluginClasses); + } + + foreach ($restClasses as $classFile) { + if (! file_exists($classFile)) { + continue; + } + require_once $classFile; $namespace = 'Services_Rest_'; $className = str_replace('.php', '', basename($classFile)); diff --git a/workflow/engine/services/rest/Case.php b/workflow/engine/services/rest/Case.php index cd26e2af8..51557fba4 100644 --- a/workflow/engine/services/rest/Case.php +++ b/workflow/engine/services/rest/Case.php @@ -2,23 +2,7 @@ class Services_Rest_Case { - public function get() - { - echo 'hello world'; - } - - public function options22() - { - echo 'opts'; - } - - public function post() - { - header('Content-Type: application/json'); - echo '{"response": "hello post"}'; - } - - protected function get11($id = '', $start=null, $limit=null, $type=null, $filter=null, $search=null, $process=null, $user=null, $status=null, $typeResource=null, $dateFrom=null, $dateTo=null) + protected function get($id = '', $start=null, $limit=null, $type=null, $filter=null, $search=null, $process=null, $user=null, $status=null, $typeResource=null, $dateFrom=null, $dateTo=null) { if (empty($id)) { // getting all records. diff --git a/workflow/public_html/sysGeneric.php b/workflow/public_html/sysGeneric.php index 055b0f5dc..35c699bcf 100755 --- a/workflow/public_html/sysGeneric.php +++ b/workflow/public_html/sysGeneric.php @@ -428,14 +428,15 @@ // disable until confirm that rest is enabled & configured on rest-config.ini file $isRestRequest = false; $confFile = ''; + $restApiClassPath = ''; // try load and getting rest configuration if (file_exists(PATH_DATA_SITE . 'rest-config.ini')) { $confFile = PATH_DATA_SITE . 'rest-config.ini'; + $restApiClassPath = PATH_DATA_SITE; } elseif (file_exists(PATH_CONFIG . 'rest-config.ini')) { $confFile = PATH_CONFIG . 'rest-config.ini'; } - if (! empty($confFile) && $restConfig = @parse_ini_file($confFile, true)) { if (array_key_exists('enable_service', $restConfig)) { if ($restConfig['enable_service'] == 'true' || $restConfig['enable_service'] == '1') { @@ -725,7 +726,7 @@ $controller->setHttpRequestData($_REQUEST); $controller->call($controllerAction); } elseif ($isRestRequest) { - G::dispatchRestService(SYS_TARGET, $restConfig); + G::dispatchRestService(SYS_TARGET, $restConfig, $restApiClassPath); } else { require_once $phpFile; }