diff --git a/composer.json b/composer.json index 47bc1a704..1f7672224 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "luracast/restler": "3.0.0-RC5", + "luracast/restler": "^3.0", "bshaffer/oauth2-server-php": "v1.0", "colosa/pmUI": "release/3.2-dev", "colosa/MichelangeloFE": "release/3.2-dev", diff --git a/composer.lock b/composer.lock index 492e7640e..5a4820190 100644 --- a/composer.lock +++ b/composer.lock @@ -192,7 +192,7 @@ }, { "name": "luracast/restler", - "version": "3.0.0-RC5", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/Luracast/Restler.git", @@ -267,7 +267,7 @@ "rest", "server" ], - "time": "2015-08-04T07:52:49+00:00" + "time": "2017-01-11T03:42:36+00:00" }, { "name": "monolog/monolog", diff --git a/framework/src/Maveriks/Extension/Restler.php b/framework/src/Maveriks/Extension/Restler.php index e3672fa9d..c4769a9f3 100644 --- a/framework/src/Maveriks/Extension/Restler.php +++ b/framework/src/Maveriks/Extension/Restler.php @@ -141,4 +141,53 @@ class Restler extends \Luracast\Restler\Restler { return $this->workspace; } + + protected function call() + { + $this->dispatch('call'); + $o = &$this->apiMethodInfo; + $accessLevel = max(\Luracast\Restler\Defaults::$apiAccessLevel, $o->accessLevel); + $object = \Luracast\Restler\Scope::get($o->className); + switch ($accessLevel) { + case 3 : //protected method + $reflectionMethod = new \ReflectionMethod( + $object, + $o->methodName + ); + $reflectionMethod->setAccessible(true); + $result = $reflectionMethod->invokeArgs( + $object, + $o->parameters + ); + break; + default : + $object = $this->reviewApiExtensions($object, $o->className); + $result = call_user_func_array(array( + $object, + $o->methodName + ), $o->parameters); + } + $this->responseData = $result; + } + + public function reviewApiExtensions($object, $className) + { + $classReflection = new \ReflectionClass($object); + $classShortName = $classReflection->getShortName(); + $registry = &\PMPluginRegistry::getSingleton(); + $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; + } + } + } + return $object; + } + } \ No newline at end of file diff --git a/workflow/engine/classes/class.plugin.php b/workflow/engine/classes/class.plugin.php index e4e5c0d6c..675963b6e 100644 --- a/workflow/engine/classes/class.plugin.php +++ b/workflow/engine/classes/class.plugin.php @@ -349,6 +349,28 @@ 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); + } + + /** + * Register a extend rest service and expose it + * + * @param string $className that is name class to extends + */ + function disableExtendsRestService($className) + { + $oPluginRegistry =& PMPluginRegistry::getSingleton(); + $oPluginRegistry->disableExtendsRestService($this->sNamespace, $className); + } + /** * Unregister a rest service * diff --git a/workflow/engine/classes/class.pluginRegistry.php b/workflow/engine/classes/class.pluginRegistry.php index cd7e0f46d..0061dcb78 100644 --- a/workflow/engine/classes/class.pluginRegistry.php +++ b/workflow/engine/classes/class.pluginRegistry.php @@ -117,6 +117,8 @@ class PMPluginRegistry */ private $_restServices = array (); + private $_restExtendServices = array (); + private $_restServiceEnabled = array(); private static $instance = null; @@ -427,6 +429,10 @@ class PMPluginRegistry if(sizeof( $this->_aOpenReassignCallback )){ unset( $this->_aOpenReassignCallback ); } + + if (sizeof($this->_restExtendServices)) { + $this->disableExtendsRestService($sNamespace); + } //unregistering javascripts from this plugin $this->unregisterJavascripts( $sNamespace ); //unregistering rest services from this plugin @@ -1458,6 +1464,60 @@ 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 + */ + 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[$sNamespace][$className] = array( + "filePath" => $classFile, + "classParent" => $className, + "classExtend" => 'Ext' . $className + ); + } + } + + /** + * Get a extend rest service class from a plugin to be served by processmaker + * + * @param string $className The service (api) class name + * @return array + */ + public function getExtendsRestService($className) + { + $responseRestExtendService = array(); + foreach ($this->_restExtendServices as $sNamespace => $restExtendService) { + if (isset($restExtendService[$className])) { + $responseRestExtendService = $restExtendService[$className]; + break; + } + } + return $responseRestExtendService; + } + + /** + * Remove a extend rest service class from a plugin to be served by processmaker + * + * @param string $sNamespace + * @param string $className The service (api) class name + * @return bool + */ + public function disableExtendsRestService($sNamespace, $className = '') + { + if (isset($this->_restExtendServices[$sNamespace][$className]) && !empty($className)) { + unset($this->_restExtendServices[$sNamespace][$className]); + } elseif (empty($className)) { + unset($this->_restExtendServices[$sNamespace]); + } + } + /** * Unregister a rest service class of a plugin *