Updating API Rest Dispatching, adding alias support from a conf api.ini file
This commit is contained in:
116
workflow/engine/src/Services/Api/ProcessMaker/Test.php
Normal file
116
workflow/engine/src/Services/Api/ProcessMaker/Test.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
namespace Services\Api\ProcessMaker;
|
||||
|
||||
use \ProcessMaker\Api;
|
||||
use \Luracast\Restler\RestException;
|
||||
|
||||
class Test extends Api
|
||||
{
|
||||
protected $data = array();
|
||||
|
||||
function __construct()
|
||||
{
|
||||
if (! isset($_SESSION['__rest_tmp__'])) {
|
||||
$this->data[1] = array(
|
||||
'id' => '1',
|
||||
'name' => 'John',
|
||||
'lastname' => 'Doe',
|
||||
'age' => '27'
|
||||
);
|
||||
$this->saveData();
|
||||
} else {
|
||||
$this->loadData();
|
||||
}
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
return array_values($this->data);
|
||||
}
|
||||
|
||||
function get($id)
|
||||
{
|
||||
if (array_key_exists($id, $this->data)) {
|
||||
return $this->data[$id];
|
||||
}
|
||||
|
||||
throw new RestException(400, "Record not found. Record with id: $id does not exist!");
|
||||
}
|
||||
|
||||
function post($request_data = NULL)
|
||||
{
|
||||
$id = count($this->data) + 1;
|
||||
$this->data[$id] = array(
|
||||
'id' => $id,
|
||||
'name' => '',
|
||||
'lastname' => '',
|
||||
'age' => ''
|
||||
);
|
||||
|
||||
if (array_key_exists('name', $request_data)) {
|
||||
$this->data[$id]['name'] = $request_data['name'];
|
||||
}
|
||||
if (array_key_exists('lastname', $request_data)) {
|
||||
$this->data[$id]['lastname'] = $request_data['lastname'];
|
||||
}
|
||||
if (array_key_exists('age', $request_data)) {
|
||||
$this->data[$id]['age'] = $request_data['age'];
|
||||
}
|
||||
|
||||
$this->saveData();
|
||||
|
||||
return $this->data[$id];
|
||||
}
|
||||
|
||||
function put($id, $request_data = NULL)
|
||||
{
|
||||
if (array_key_exists($id, $this->data)) {
|
||||
if (array_key_exists('name', $request_data)) {
|
||||
$this->data[$id] = $request_data['name'];
|
||||
}
|
||||
if (array_key_exists('lastname', $request_data)) {
|
||||
$this->data[$id] = $request_data['lastname'];
|
||||
}
|
||||
if (array_key_exists('age', $request_data)) {
|
||||
$this->data[$id] = $request_data['age'];
|
||||
}
|
||||
$this->saveData();
|
||||
|
||||
return $this->data[$id];
|
||||
} else {
|
||||
throw new RestException(400, "Record not found. Record with id: $id does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
function delete($id)
|
||||
{
|
||||
if (array_key_exists($id, $this->data)) {
|
||||
$row = $this->data[$id];
|
||||
unset($this->data[$id]);
|
||||
$this->saveData();
|
||||
|
||||
return $row;
|
||||
} else {
|
||||
throw new RestException(400, "Record not found. Record with id: $id does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @url GET /testing/sample/:param
|
||||
*/
|
||||
function doOverride($param)
|
||||
{
|
||||
return $param;
|
||||
}
|
||||
|
||||
/* Private methods */
|
||||
private function loadData()
|
||||
{
|
||||
$this->data = $_SESSION['__rest_tmp__'];
|
||||
}
|
||||
|
||||
private function saveData()
|
||||
{
|
||||
$_SESSION['__rest_tmp__'] = $this->data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user