up observations
This commit is contained in:
@@ -162,7 +162,7 @@ class Restler extends \Luracast\Restler\Restler
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
$object = $this->reviewApiExtensions($o->className);
|
$object = $this->reviewApiExtensions($object, $o->className);
|
||||||
$result = call_user_func_array(array(
|
$result = call_user_func_array(array(
|
||||||
$object,
|
$object,
|
||||||
$o->methodName
|
$o->methodName
|
||||||
@@ -171,20 +171,17 @@ class Restler extends \Luracast\Restler\Restler
|
|||||||
$this->responseData = $result;
|
$this->responseData = $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reviewApiExtensions($className)
|
public function reviewApiExtensions($object, $className)
|
||||||
{
|
{
|
||||||
$object = \Luracast\Restler\Scope::get($className);
|
|
||||||
$classReflection = new \ReflectionClass($object);
|
$classReflection = new \ReflectionClass($object);
|
||||||
$classShortName = $classReflection->getShortName();
|
$classShortName = $classReflection->getShortName();
|
||||||
\G::LoadClass('pluginRegistry');
|
|
||||||
$registry = \PMPluginRegistry::getSingleton();
|
$registry = \PMPluginRegistry::getSingleton();
|
||||||
$pluginsActive = $registry->getEnabledPlugins();
|
$pluginsApiExtend = $registry->getExtendsRestService($classShortName);
|
||||||
foreach ($pluginsActive as $name => $plugin) {
|
if ($pluginsApiExtend) {
|
||||||
$pathExtensions = PATH_PLUGINS . $plugin . PATH_SEP . 'src' . PATH_SEP . 'Services' . PATH_SEP . 'Ext' . PATH_SEP;
|
$classFilePath = $pluginsApiExtend['filePath'];
|
||||||
$sFileExits = file_exists($pathExtensions . 'Ext' . $classShortName . '.php');
|
if(file_exists($classFilePath)) {
|
||||||
if ($sFileExits) {
|
require_once($classFilePath);
|
||||||
require_once($pathExtensions . 'Ext' . $classShortName . '.php');
|
$classExtName = $pluginsApiExtend['classExtend'];
|
||||||
$classExtName = 'Ext' . $classShortName;
|
|
||||||
$newObjectExt = new $classExtName();
|
$newObjectExt = new $classExtName();
|
||||||
if (is_subclass_of($newObjectExt, $className)) {
|
if (is_subclass_of($newObjectExt, $className)) {
|
||||||
$object = $newObjectExt;
|
$object = $newObjectExt;
|
||||||
|
|||||||
@@ -349,6 +349,17 @@ class PMPlugin
|
|||||||
$oPluginRegistry->registerRestService($this->sNamespace);
|
$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
|
* Unregister a rest service
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -117,6 +117,8 @@ class PMPluginRegistry
|
|||||||
*/
|
*/
|
||||||
private $_restServices = array ();
|
private $_restServices = array ();
|
||||||
|
|
||||||
|
private $_restExtendServices = array ();
|
||||||
|
|
||||||
private $_restServiceEnabled = array();
|
private $_restServiceEnabled = array();
|
||||||
|
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
@@ -1458,6 +1460,38 @@ class PMPluginRegistry
|
|||||||
return true;
|
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
|
* Unregister a rest service class of a plugin
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user