New feature for Gulliver framework to support Controllers & HttpProxyController classes handling
This commit is contained in:
@@ -23,15 +23,15 @@
|
||||
*
|
||||
*/
|
||||
session_start();
|
||||
if( ! isset($_GET['p']) )
|
||||
|
||||
if ( isset ( $_SESSION['phpFileNotFound'] ) )
|
||||
$uri = $_SESSION['phpFileNotFound'];
|
||||
else if ( isset ( $_GET['l'] ) )
|
||||
$uri = $_GET['l'];
|
||||
else
|
||||
$uri = 'undefined';
|
||||
else
|
||||
$uri = $_GET['p'];
|
||||
|
||||
$referer = isset ( $_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
|
||||
$referer = isset ( $_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_SESSION['phpLastFileFound'];
|
||||
|
||||
$ERROR_TEXT = "404 Not Found ";
|
||||
$ERROR_DESCRIPTION = "
|
||||
|
||||
115
gulliver/system/class.controller.php
Normal file
115
gulliver/system/class.controller.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* Controller
|
||||
* @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com>
|
||||
* @package gulliver.system
|
||||
* @access private
|
||||
*/
|
||||
class Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array - private array to store proxy data
|
||||
*/
|
||||
private $__data__ = array();
|
||||
|
||||
/**
|
||||
* @var object - private object to store the http request data
|
||||
*/
|
||||
private $__request__;
|
||||
|
||||
private $headPublisher;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->headPublisher = headPublisher::getSingleton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic setter method
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
//echo "Setting '$name' to '$value'\n";
|
||||
$this->__data__[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic getter method
|
||||
*
|
||||
* @param string $name
|
||||
* @return string or NULL if the internal var doesn't exist
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
//echo "Getting '$name'\n";
|
||||
if (array_key_exists($name, $this->__data__)) {
|
||||
return $this->__data__[$name];
|
||||
}
|
||||
|
||||
$trace = debug_backtrace();
|
||||
trigger_error(
|
||||
'Undefined property via __get(): ' . $name .
|
||||
' in ' . $trace[0]['file'] .
|
||||
' on line ' . $trace[0]['line'],
|
||||
E_USER_NOTICE);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic isset method
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function __isset($name)
|
||||
{
|
||||
//echo "Is '$name' set?\n";
|
||||
return isset($this->__data__[$name]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Magic unset method
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function __unset($name)
|
||||
{
|
||||
//echo "Unsetting '$name'\n";
|
||||
unset($this->__data__[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* call to execute a internal proxy method and handle its exceptions
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function call($name)
|
||||
{
|
||||
//echo __CLASS__;
|
||||
try {
|
||||
|
||||
$this->$name($this->__request__);
|
||||
|
||||
} catch (Exception $e) {
|
||||
new PMException($e->getMessage(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the http request data
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function setHttpRequestData($data)
|
||||
{
|
||||
if( is_array($data) ) {
|
||||
while( $var = each($data) )
|
||||
$this->__request__->$var['key'] = $var['value'];
|
||||
} else
|
||||
$this->__request__ = $data;
|
||||
}
|
||||
}
|
||||
@@ -1165,7 +1165,7 @@ class G
|
||||
}
|
||||
|
||||
$_SESSION['phpFileNotFound'] = $file;
|
||||
G::header("location: /errors/error404.php?p=$filename");
|
||||
G::header("location: /errors/error404.php?l=".$_SERVER['REQUEST_URI']);
|
||||
}
|
||||
|
||||
switch ( strtolower($typefile ) ) {
|
||||
|
||||
116
gulliver/system/class.httpProxyController.php
Executable file
116
gulliver/system/class.httpProxyController.php
Executable file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* HttpProxyController
|
||||
* @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com>
|
||||
* @package gulliver.system
|
||||
* @access private
|
||||
*/
|
||||
class HttpProxyController {
|
||||
|
||||
|
||||
/**
|
||||
* @var array - private array to store proxy data
|
||||
*/
|
||||
private $__data__ = array();
|
||||
|
||||
/**
|
||||
* @var object - private object to store the http request data
|
||||
*/
|
||||
private $__request__;
|
||||
|
||||
|
||||
/**
|
||||
* Magic setter method
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
//echo "Setting '$name' to '$value'\n";
|
||||
$this->__data__[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic getter method
|
||||
*
|
||||
* @param string $name
|
||||
* @return string or NULL if the internal var doesn't exist
|
||||
*/
|
||||
public function __get($name) {
|
||||
//echo "Getting '$name'\n";
|
||||
if (array_key_exists($name, $this->__data__)) {
|
||||
return $this->__data__[$name];
|
||||
}
|
||||
|
||||
$trace = debug_backtrace();
|
||||
trigger_error(
|
||||
'Undefined property via __get(): ' . $name .
|
||||
' in ' . $trace[0]['file'] .
|
||||
' on line ' . $trace[0]['line'],
|
||||
E_USER_NOTICE);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic isset method
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function __isset($name) {
|
||||
//echo "Is '$name' set?\n";
|
||||
return isset($this->__data__[$name]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Magic unset method
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function __unset($name) {
|
||||
//echo "Unsetting '$name'\n";
|
||||
unset($this->__data__[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* call to execute a internal proxy method and handle its exceptions
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function call($name)
|
||||
{
|
||||
//echo __CLASS__;
|
||||
try {
|
||||
$this->$name($this->__request__);
|
||||
$result = $this->__data__;
|
||||
} catch (Exception $e) {
|
||||
$result->success = false;
|
||||
$result->msg = $e->getMessage();
|
||||
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 = $error;
|
||||
|
||||
$result->exception->class = get_class($e);
|
||||
$result->exception->code = $e->getCode();
|
||||
}
|
||||
print json_encode($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the http request data
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function setHttpRequestData($data)
|
||||
{
|
||||
if( is_array($data) ) {
|
||||
while( $var = each($data) )
|
||||
$this->__request__->$var['key'] = $var['value'];
|
||||
} else
|
||||
$this->__request__ = $data;
|
||||
}
|
||||
}
|
||||
17
gulliver/system/class.pmException.php
Normal file
17
gulliver/system/class.pmException.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* HttpProxyController
|
||||
* @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com>
|
||||
* @package gulliver.system
|
||||
* @access public
|
||||
*/
|
||||
class PMException extends Exception
|
||||
{
|
||||
public function __construct($message, $code = 0, $previous = null) {
|
||||
parent::__construct($message, 1, $previous);
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,7 @@
|
||||
define( 'PATH_WORKFLOW_MSSQL_DATA', PATH_CORE . 'data' . PATH_SEP.'mssql'.PATH_SEP);
|
||||
define( 'PATH_RBAC_MSSQL_DATA', PATH_RBAC_CORE . 'data' . PATH_SEP.'mssql'.PATH_SEP);
|
||||
|
||||
define( 'PATH_CONTROLLERS', PATH_CORE . 'controllers' . PATH_SEP );
|
||||
|
||||
//************ include Gulliver Class **************
|
||||
require_once( PATH_GULLIVER . PATH_SEP . 'class.g.php');
|
||||
|
||||
@@ -237,6 +237,9 @@ $startingTime = array_sum(explode(' ',microtime()));
|
||||
G::LoadSystem("xmlMenu");
|
||||
G::LoadSystem('dvEditor');
|
||||
G::LoadSystem('table');
|
||||
G::LoadSystem('controller');
|
||||
G::LoadSystem('httpProxyController');
|
||||
G::LoadSystem('pmException');
|
||||
//G::LoadSystem('pagedTable');
|
||||
|
||||
//************** Installer, redirect to install if we don't have a valid shared data folder ***************/
|
||||
@@ -434,10 +437,11 @@ $startingTime = array_sum(explode(' ',microtime()));
|
||||
}
|
||||
|
||||
//the index.php file, this new feature will allow automatically redirects to valid php file inside any methods folder
|
||||
/* DEPRECATED
|
||||
if ( SYS_TARGET == '' ) {
|
||||
$phpFile = str_replace ( '.php', 'index.php', $phpFile );
|
||||
$phpFile = include ( $phpFile );
|
||||
}
|
||||
}*/
|
||||
$bWE = false;
|
||||
if ( substr(SYS_COLLECTION , 0,8) === 'gulliver' ) {
|
||||
$phpFile = PATH_GULLIVER_HOME . 'methods/' . substr( SYS_COLLECTION , 8) . SYS_TARGET.'.php';
|
||||
@@ -463,15 +467,29 @@ $startingTime = array_sum(explode(' ',microtime()));
|
||||
$bWE = true;
|
||||
//$phpFile = PATH_DATA_SITE . 'public' . PATH_SEP . SYS_COLLECTION . PATH_SEP . $auxPart[ count($auxPart)-1];
|
||||
}
|
||||
if ( ! file_exists( $phpFile ) ) {
|
||||
$_SESSION['phpFileNotFound'] = $phpFile;
|
||||
|
||||
//erik: verify if it is a Controller Class or httpProxyController Class
|
||||
$isControllerCall = false;
|
||||
|
||||
if( is_file(PATH_CONTROLLERS . SYS_COLLECTION . '.php') ) {
|
||||
require_once PATH_CONTROLLERS . SYS_COLLECTION . '.php';
|
||||
$controllerClass = SYS_COLLECTION;
|
||||
//if the method name is empty set default to index method
|
||||
$controllerAction = SYS_TARGET != '' ? SYS_TARGET : 'index';
|
||||
//if the method exists
|
||||
if( is_callable(Array($controllerClass, $controllerAction)) ) {
|
||||
$isControllerCall = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $isControllerCall && ! file_exists( $phpFile ) ) {
|
||||
$_SESSION['phpFileNotFound'] = $_SERVER['REQUEST_URI'];
|
||||
print $phpFile;
|
||||
header ("location: /errors/error404.php");
|
||||
die;
|
||||
}
|
||||
}
|
||||
//G::pr($_SESSION);
|
||||
//G::dump($avoidChangedWorkspaceValidation);die;
|
||||
|
||||
//redirect to login, if user changed the workspace in the URL
|
||||
if( ! $avoidChangedWorkspaceValidation && isset( $_SESSION['WORKSPACE'] ) && $_SESSION['WORKSPACE'] != SYS_SYS) {
|
||||
$_SESSION['WORKSPACE'] = SYS_SYS;
|
||||
@@ -536,7 +554,20 @@ $startingTime = array_sum(explode(' ',microtime()));
|
||||
}
|
||||
}
|
||||
}
|
||||
$_SESSION['phpLastFileFound'] = $_SERVER['REQUEST_URI'];
|
||||
|
||||
/***
|
||||
* New feature for Gulliver framework to support Controllers & HttpProxyController classes handling
|
||||
*
|
||||
* @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com>
|
||||
*/
|
||||
if( $isControllerCall ) { //Instance the Controller object and call the request method
|
||||
$controller = new $controllerClass();
|
||||
$controller->setHttpRequestData($_REQUEST);
|
||||
$controller->call($controllerAction);
|
||||
} else
|
||||
require_once( $phpFile );
|
||||
|
||||
if ( defined('SKIP_HEADERS') ) {
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", mktime( 0,0,0,date('m'),date('d'),date('Y') + 1) ) . " GMT");
|
||||
header('Cache-Control: public');
|
||||
|
||||
Reference in New Issue
Block a user