Updating API Rest Dispatching, adding alias support from a conf api.ini file

This commit is contained in:
Erik Amaru Ortiz
2013-11-26 17:17:36 -04:00
parent fca8338b24
commit 1faafa8ee4
103 changed files with 218 additions and 1160 deletions

View 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;
}
}