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
This commit is contained in:
@@ -5169,7 +5169,7 @@ function getDirectorySize($path,$maxmtime=0)
|
||||
*
|
||||
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com>
|
||||
*/
|
||||
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));
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user