main changes to enable register rest api endpoints from plugins
1. Enable rest api registering feature on main plugin file
i.e, if I have a plugin named "erik", so we have a file named workflow/engine/plugins/erik.php
and a folder workflow/engine/plugins/erik/
- inside of setup method of plugin main class set: $this->enableRestService(true);
---- file: erik.php ----
class erikPlugin extends PMPlugin
{
...
public function setup()
{
$this->registerMenu("processmaker", "menuerik.php");
...
$this->enableRestService(true); // <- this line enable Rest Service dispatching feature
}
...
2. Create a folder: workflow/engine/plugins/erik/src/Services/Api/
$ mkdir -p workflow/engine/plugins/erik/src/Services/Api/
3. Create a Restler class inside the folder created above
i.e. creating a Hello class.
---- file: workflow/engine/plugins/erik/src/Services/Api/Hello.php -----
<?php
namespace Services\Api;
use Luracast\Restler\RestException;
use ProcessMaker\Services\Api;
use \ProcessMaker\Util;
/**
* @protected
*/
class Hello extends Api
{
/**
* @url GET /world
*/
public function world()
{
try {
$hello = array(
'message' => 'Hello world'
);
return $hello;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}
---------- end file ---------
4. Disable and enable the plugin named "erik" on ProcessMaker Admin Interface
5. Use the Rest Api defined inside the plugin
you can access from a url something like that:
format: http://<SERVER-ADDR>/api/1.0/<WORKSPACE>/plugin-<THE-PLUGIN-NAME>/hello/world
i.e.
http://processmaker/api/1.0/workflow/plugin-erik/hello/world
Note.- to access this url that has the protected attribute into the class
you need provide the access token into request header.
This commit is contained in:
@@ -277,12 +277,15 @@ class PMPluginRegistry
|
||||
$pluginSrcDir = PATH_PLUGINS . $detail->sNamespace . PATH_SEP . 'src';
|
||||
|
||||
if (is_dir($pluginSrcDir)) {
|
||||
Bootstrap::registerDir($detail->sNamespace.'/src', $pluginSrcDir);
|
||||
//Bootstrap::registerDir($detail->sNamespace.'/src', $pluginSrcDir);
|
||||
$loader = \Maveriks\Util\ClassLoader::getInstance();
|
||||
$loader->add($pluginSrcDir);
|
||||
}
|
||||
|
||||
if (array_key_exists($detail->sNamespace, $this->_restServiceEnabled)
|
||||
&& $this->_restServiceEnabled[$detail->sNamespace] == true
|
||||
) {
|
||||
|
||||
$oPlugin->registerRestService();
|
||||
}
|
||||
|
||||
@@ -1400,7 +1403,6 @@ class PMPluginRegistry
|
||||
|
||||
foreach ($classesList as $classFile) {
|
||||
if (pathinfo($classFile, PATHINFO_EXTENSION) === 'php') {
|
||||
|
||||
$ns = str_replace(
|
||||
DIRECTORY_SEPARATOR,
|
||||
'\\',
|
||||
@@ -1413,6 +1415,8 @@ class PMPluginRegistry
|
||||
"filepath" => $classFile,
|
||||
"namespace" => $ns
|
||||
);
|
||||
|
||||
\Maveriks\WebApplication::purgeRestApiCache(basename(PATH_DATA_SITE));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1601,4 +1605,3 @@ class PMPluginRegistry
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user