up observations

This commit is contained in:
qronald
2017-02-14 15:23:41 -04:00
parent f4356a0c5c
commit d8f160cfa0
3 changed files with 53 additions and 11 deletions

View File

@@ -162,7 +162,7 @@ class Restler extends \Luracast\Restler\Restler
);
break;
default :
$object = $this->reviewApiExtensions($o->className);
$object = $this->reviewApiExtensions($object, $o->className);
$result = call_user_func_array(array(
$object,
$o->methodName
@@ -171,20 +171,17 @@ class Restler extends \Luracast\Restler\Restler
$this->responseData = $result;
}
public function reviewApiExtensions($className)
public function reviewApiExtensions($object, $className)
{
$object = \Luracast\Restler\Scope::get($className);
$classReflection = new \ReflectionClass($object);
$classShortName = $classReflection->getShortName();
\G::LoadClass('pluginRegistry');
$registry = \PMPluginRegistry::getSingleton();
$pluginsActive = $registry->getEnabledPlugins();
foreach ($pluginsActive as $name => $plugin) {
$pathExtensions = PATH_PLUGINS . $plugin . PATH_SEP . 'src' . PATH_SEP . 'Services' . PATH_SEP . 'Ext' . PATH_SEP;
$sFileExits = file_exists($pathExtensions . 'Ext' . $classShortName . '.php');
if ($sFileExits) {
require_once($pathExtensions . 'Ext' . $classShortName . '.php');
$classExtName = 'Ext' . $classShortName;
$pluginsApiExtend = $registry->getExtendsRestService($classShortName);
if ($pluginsApiExtend) {
$classFilePath = $pluginsApiExtend['filePath'];
if(file_exists($classFilePath)) {
require_once($classFilePath);
$classExtName = $pluginsApiExtend['classExtend'];
$newObjectExt = new $classExtName();
if (is_subclass_of($newObjectExt, $className)) {
$object = $newObjectExt;

View File

@@ -349,6 +349,17 @@ class PMPlugin
$oPluginRegistry->registerRestService($this->sNamespace);
}
/**
* Register a extend rest service and expose it
*
* @param string $className that is name class to extends
*/
function registerExtendsRestService($className)
{
$oPluginRegistry =& PMPluginRegistry::getSingleton();
$oPluginRegistry->registerExtendsRestService($this->sNamespace, $className);
}
/**
* Unregister a rest service
*

View File

@@ -117,6 +117,8 @@ class PMPluginRegistry
*/
private $_restServices = array ();
private $_restExtendServices = array ();
private $_restServiceEnabled = array();
private static $instance = null;
@@ -1458,6 +1460,38 @@ class PMPluginRegistry
return true;
}
/**
* Register a extend rest service class from a plugin to be served by processmaker
*
* @param string $sNamespace The namespace for the plugin
* @param string $className The service (api) class name
* @return bool
*/
public function registerExtendsRestService($sNamespace, $className)
{
$baseSrcPluginPath = PATH_PLUGINS . $sNamespace . PATH_SEP . "src";
$apiPath = PATH_SEP . "Services" . PATH_SEP . "Ext" . PATH_SEP;
$classFile = $baseSrcPluginPath . $apiPath . 'Ext' . $className . '.php';
if(file_exists($classFile)){
$this->_restExtendServices[$className] = array(
"filePath" => $classFile,
"classParent" => $className,
"classExtend" => 'Ext' . $className
);
}
return true;
}
/**
* Get a extend rest service class from a plugin to be served by processmaker
*
* @param string $className The service (api) class name
* @return bool
*/
public function getExtendsRestService($className)
{
return isset($this->_restExtendServices[$className]) ? $this->_restExtendServices[$className] : array();
}
/**
* Unregister a rest service class of a plugin
*