Files
luos/gulliver/system/class.httpProxyController.php

161 lines
3.5 KiB
PHP
Raw Permalink Normal View History

<?php
2023-03-24 17:55:53 +00:00
use ProcessMaker\Exception\RBACException;
/**
* HttpProxyController
*
* @package gulliver.system
* @access private
*/
class HttpProxyController
{
/**
*
* @var array - private array to store proxy data
*/
2017-12-04 13:25:35 +00:00
private $__data__ = array();
/**
*
* @var object - private object to store the http request data
*/
private $__request__;
public $jsonResponse = true;
2011-08-19 16:47:44 -04:00
private $sendResponse = true;
2017-12-04 13:25:35 +00:00
public function __construct()
{
$this->__request__ = new stdclass();
}
/**
* Magic setter method
*
* @param string $name
* @param string $value
*/
2017-12-04 13:25:35 +00:00
public function __set($name, $value)
{
$this->__data__[$name] = $value;
}
/**
* Magic getter method
*
* @param string $name
* @return string or NULL if the internal var doesn't exist
*/
2017-12-04 13:25:35 +00:00
public function __get($name)
{
2017-12-04 13:25:35 +00:00
if (array_key_exists($name, $this->__data__)) {
return $this->__data__[$name];
}
}
/**
* Magic isset method
*
* @param string $name
*/
2017-12-04 13:25:35 +00:00
public function __isset($name)
{
2017-12-04 13:25:35 +00:00
return isset($this->__data__[$name]);
}
/**
* Magic unset method
*
* @param string $name
*/
2017-12-04 13:25:35 +00:00
public function __unset($name)
{
//echo "Unsetting '$name'\n";
2017-12-04 13:25:35 +00:00
unset($this->__data__[$name]);
}
/**
* call to execute a internal proxy method and handle its exceptions
*
* @param string $name
*/
2017-12-04 13:25:35 +00:00
public function call($name)
{
$result = new stdClass();
try {
2017-12-04 13:25:35 +00:00
$result = $this->$name($this->__request__);
if (! $this->jsonResponse) {
return null;
}
if (! $result) {
$result = $this->__data__;
}
2023-03-24 17:55:53 +00:00
} catch (RBACException $e) {
// If is a RBAC exception bubble up...
throw $e;
} catch (Exception $e) {
$result->success = false;
$result->message = $result->msg = $e->getMessage();
2017-12-04 13:25:35 +00:00
switch (get_class($e)) {
case 'Exception':
$error = "SYSTEM ERROR";
break;
case 'PMException':
$error = "PROCESSMAKER ERROR";
break;
case 'PropelException':
$error = "DATABASE ERROR";
break;
case 'UserException':
$error = "USER ERROR";
break;
}
$result->error = $e->getMessage();
$result->exception = new stdClass();
2017-12-04 13:25:35 +00:00
$result->exception->class = get_class($e);
$result->exception->code = $e->getCode();
$result->exception->trace = $e->getTraceAsString();
}
2011-08-19 16:47:44 -04:00
if ($this->sendResponse) {
2017-12-04 13:25:35 +00:00
print G::json_encode($result);
2011-08-19 16:47:44 -04:00
}
}
/**
* Set the http request data
*
* @param array $data
*/
2017-12-04 13:25:35 +00:00
public function setHttpRequestData($data)
{
2017-12-04 13:25:35 +00:00
if (is_array($data)) {
2019-11-27 15:50:26 -04:00
foreach ($data as $key => $value) {
$this->__request__->{$key} = $value;
}
} else {
$this->__request__ = $data;
}
}
2011-08-19 16:47:44 -04:00
2017-12-04 13:25:35 +00:00
public function setJsonResponse($bool)
{
$this->jsonResponse = $bool;
}
2011-08-19 16:47:44 -04:00
/**
* Send response to client
*
2011-08-19 16:47:44 -04:00
* @param boolean $val
*/
2017-12-04 13:25:35 +00:00
public function setSendResponse($val)
2011-08-19 16:47:44 -04:00
{
$this->sendResponse = $val;
}
}