PM Rest Feature: added plugins support & more improvements
from a plugin a rest class can be registered now:
on setup method add the following:
---
$this->registerRestService('Sample', [optional string: $path]);
--
and create the folder PATH_PLUGIN . /your_plugin/classes/rest
next add a class with the flowing characteristics:
<?php
class Plugin_Services_Rest_Sample
{
public function get()
{
return 'hello world';
}
}
A class prefixed with Plugin_Services_Rest_
and add the corresponding methods for a Restler api
(http://luracast.com/products/restler/)
Finally on process maker will be exposed as:
via GET: http://127.0.0.1/rest/workflow/sample
This commit is contained in:
@@ -95,6 +95,11 @@ class PMPluginRegistry {
|
||||
*/
|
||||
private $_aJavascripts = array();
|
||||
|
||||
/**
|
||||
* Contains all rest services classes from plugins
|
||||
*/
|
||||
private $_restServices = array();
|
||||
|
||||
static private $instance = NULL;
|
||||
|
||||
/**
|
||||
@@ -1224,6 +1229,67 @@ class PMPluginRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a 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
|
||||
* @param string $path (optional) the class file path, if it is not set the system will try resolve the
|
||||
* file path from its classname.
|
||||
*/
|
||||
public function registerRestService($sNamespace, $classname, $path = '')
|
||||
{
|
||||
$restService = new StdClass();
|
||||
$restService->sNamespace = $sNamespace;
|
||||
$restService->classname = $classname;
|
||||
|
||||
if (empty($path)) {
|
||||
$path = PATH_PLUGINS . $restService->sNamespace . "/classes/rest/$classname.php";
|
||||
}
|
||||
|
||||
if (! file_exists($path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$restService->path = $path;
|
||||
$this->_restServices[] = $restService;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a rest service class of a plugin
|
||||
*
|
||||
* @param string $sNamespace The namespace for the plugin
|
||||
* @param string $classname The service (api) class name
|
||||
*/
|
||||
public function unregisterRestService($sNamespace, $classname)
|
||||
{
|
||||
foreach ($this->_restServices as $i => $service) {
|
||||
if ($sNamespace == $service->sNamespace) {
|
||||
unset($this->_restServices[$i]);
|
||||
}
|
||||
}
|
||||
// Re-index when all js were unregistered
|
||||
$this->_restServices = array_values($this->_restServices);
|
||||
}
|
||||
|
||||
public function getRegisteredRestServices()
|
||||
{
|
||||
return $this->_restServices;
|
||||
}
|
||||
|
||||
public function getRegisteredRestClassFiles()
|
||||
{
|
||||
$restClassFiles = array();
|
||||
|
||||
foreach ($this->_restServices as $restService) {
|
||||
$restClassFiles[] = $restService->path;
|
||||
}
|
||||
|
||||
return $restClassFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* return all dashboard pages
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user