Adding Rest Api Service Support
Rest Service on plugins
-----------------------
1. enable service
add the following line in plugin __constructor main class
$this->enableRestService(true);
2. Create the sources directory structure by example:
if you plugin is named myPlugin
myPlugin
|--src
|--Services
|--Api
|--MyPlugin
|--Test.php
Where Test.php is a Restler class
This commit is contained in:
36
workflow/engine/src/ProcessMaker/Services/Api.php
Normal file
36
workflow/engine/src/ProcessMaker/Services/Api.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Services;
|
||||
|
||||
class Api
|
||||
{
|
||||
private static $workspace;
|
||||
private static $userId;
|
||||
|
||||
const STAT_CREATED = 201;
|
||||
const STAT_APP_EXCEPTION = 400;
|
||||
|
||||
public function __costruct()
|
||||
{
|
||||
self::$workspace = null;
|
||||
}
|
||||
|
||||
public static function setWorkspace($workspace)
|
||||
{
|
||||
self::$workspace = $workspace;
|
||||
}
|
||||
|
||||
public function getWorkspace()
|
||||
{
|
||||
return self::$workspace;
|
||||
}
|
||||
|
||||
public static function setUserId($userId)
|
||||
{
|
||||
self::$userId = $userId;
|
||||
}
|
||||
|
||||
public function getUserId()
|
||||
{
|
||||
return \Services\Api\OAuth2\Server::getUserId();
|
||||
}
|
||||
}
|
||||
40
workflow/engine/src/ProcessMaker/Util/Logger.php
Normal file
40
workflow/engine/src/ProcessMaker/Util/Logger.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Util;
|
||||
|
||||
class Logger
|
||||
{
|
||||
private static $instance;
|
||||
private $logFile;
|
||||
private $fp;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
$this->logFile = sys_get_temp_dir() . '/processmaker.log';
|
||||
$this->fp = fopen($this->logFile, "a+");
|
||||
}
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$instance)) {
|
||||
self::$instance = new Logger();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function setLog($data)
|
||||
{
|
||||
if (! is_string($data)) {
|
||||
$data = print_r($data, true);
|
||||
}
|
||||
|
||||
fwrite($this->fp, "PM LOG: ".date('Y-m-d H:i:s') . " " . $data . PHP_EOL);
|
||||
}
|
||||
|
||||
public static function log($data)
|
||||
{
|
||||
$me = Logger::getInstance();
|
||||
$me->setLog($data);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace Services\Api\ProcessMaker;
|
||||
|
||||
use \ProcessMaker\Api;
|
||||
use \ProcessMaker\Services\Api;
|
||||
use \Luracast\Restler\RestException;
|
||||
|
||||
//TODO we need Refactor this class
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace Services\Api\ProcessMaker\Project;
|
||||
|
||||
use \ProcessMaker\Api;
|
||||
use \ProcessMaker\Services\Api;
|
||||
use \Luracast\Restler\RestException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,42 +1,9 @@
|
||||
<?php
|
||||
namespace Services\Api\ProcessMaker\Project\Activity;
|
||||
|
||||
use \ProcessMaker\Api;
|
||||
use \ProcessMaker\Services\Api;
|
||||
use \Luracast\Restler\RestException;
|
||||
|
||||
class StepStructure
|
||||
{
|
||||
/**
|
||||
* @var string {@from body}{@min 32}{@max 32}
|
||||
*/
|
||||
public $step_uid;
|
||||
|
||||
/**
|
||||
* @var string {@from body}{@choice DYNAFORM,INPUT_DOCUMENT,OUTPUT_DOCUMENT}
|
||||
*/
|
||||
public $step_type_obj;
|
||||
|
||||
/**
|
||||
* @var string {@from body}{@min 32}{@max 32}
|
||||
*/
|
||||
public $step_uid_obj;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $step_condition;
|
||||
|
||||
/**
|
||||
* @var int {@from body}{@min 1}
|
||||
*/
|
||||
public $step_position;
|
||||
|
||||
/**
|
||||
* @var string {@from body}{@choice EDIT,VIEW}
|
||||
*/
|
||||
public $step_mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Project\Activity\Step Api Controller
|
||||
*
|
||||
@@ -122,3 +89,35 @@ class Step extends Api
|
||||
}
|
||||
}
|
||||
|
||||
class StepStructure
|
||||
{
|
||||
/**
|
||||
* @var string {@from body}{@min 32}{@max 32}
|
||||
*/
|
||||
public $step_uid;
|
||||
|
||||
/**
|
||||
* @var string {@from body}{@choice DYNAFORM,INPUT_DOCUMENT,OUTPUT_DOCUMENT}
|
||||
*/
|
||||
public $step_type_obj;
|
||||
|
||||
/**
|
||||
* @var string {@from body}{@min 32}{@max 32}
|
||||
*/
|
||||
public $step_uid_obj;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $step_condition;
|
||||
|
||||
/**
|
||||
* @var int {@from body}{@min 1}
|
||||
*/
|
||||
public $step_position;
|
||||
|
||||
/**
|
||||
* @var string {@from body}{@choice EDIT,VIEW}
|
||||
*/
|
||||
public $step_mode;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace Services\Api\ProcessMaker;
|
||||
|
||||
use \ProcessMaker\Api;
|
||||
use \ProcessMaker\Services\Api;
|
||||
use \Luracast\Restler\RestException;
|
||||
|
||||
class Test extends Api
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace Services\Api\ProcessMaker;
|
||||
|
||||
use \ProcessMaker\Api;
|
||||
use \ProcessMaker\Services\Api;
|
||||
use \Luracast\Restler\RestException;
|
||||
|
||||
class Test2 extends Api
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace Services\Api\ProcessMaker;
|
||||
|
||||
use \ProcessMaker\Api;
|
||||
use \ProcessMaker\Services\Api;
|
||||
use \Luracast\Restler\RestException;
|
||||
|
||||
class Test3 extends Api
|
||||
|
||||
Reference in New Issue
Block a user