FIX for multiple request to Rest API
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace Maveriks\Pattern\Mvc;
|
||||
|
||||
use Maveriks\Util\Common;
|
||||
|
||||
class SmartyView extends View
|
||||
{
|
||||
protected $smarty;
|
||||
@@ -13,8 +15,13 @@ class SmartyView extends View
|
||||
$this->smarty = new \Smarty();
|
||||
$this->smarty->compile_dir = defined('PATH_SMARTY_C')? PATH_SMARTY_C : sys_get_temp_dir();
|
||||
$this->smarty->cache_dir = defined('PATH_SMARTY_CACHE')? PATH_SMARTY_CACHE : sys_get_temp_dir();
|
||||
//$this->smarty->config_dir = PATH_THIRDPARTY . 'smarty/configs';
|
||||
//$this->smarty->register_function('translate', 'translate');
|
||||
|
||||
if (! is_dir($this->smarty->compile_dir)) {
|
||||
Common::mk_dir($this->smarty->compile_dir);
|
||||
}
|
||||
if (! is_dir($this->smarty->cache_dir)) {
|
||||
Common::mk_dir($this->smarty->cache_dir);
|
||||
}
|
||||
}
|
||||
|
||||
public function assign($name, $value)
|
||||
|
||||
@@ -96,8 +96,6 @@ class WebApplication
|
||||
*/
|
||||
public function route()
|
||||
{
|
||||
$this->requestUri = strlen($this->requestUri) > 1? rtrim($this->requestUri, '/'): $this->requestUri;
|
||||
|
||||
if ($this->requestUri === "/") {
|
||||
if (file_exists("index.html")) {
|
||||
return self::RUNNING_INDEX;
|
||||
@@ -118,34 +116,49 @@ class WebApplication
|
||||
return self::RUNNING_WORKFLOW;
|
||||
}
|
||||
|
||||
/*$workspace = $uriParts[1];
|
||||
$class = 'oauth2';
|
||||
$action = isset($uriParts[3])? $uriParts[3]: 'index';*/
|
||||
|
||||
$uriTemp = explode('/', $_SERVER['REQUEST_URI']);
|
||||
array_shift($uriTemp);
|
||||
$workspace = array_shift($uriTemp);
|
||||
$_SERVER['REQUEST_URI'] = '/' . implode('/', $uriTemp);
|
||||
|
||||
$this->loadEnvironment($workspace);
|
||||
$this->configureRest($workspace, '1.0');
|
||||
//var_dump(class_exists('ProcessMaker\\Services\\OAuth2\\Server'));
|
||||
$this->rest->addAPIClass('\ProcessMaker\\Services\\OAuth2\\Server', 'oauth2');
|
||||
$this->rest->handle();
|
||||
|
||||
/*
|
||||
// $pmOauthClientId - contains PM Local OAuth Id (Web Designer)
|
||||
$pmOauthClientId = 'x-pm-local-client';
|
||||
|
||||
$this->loadEnvironment($workspace);
|
||||
// Setting current workspace to Api class
|
||||
Services\Api::setWorkspace($workspace);
|
||||
$cacheDir = defined("PATH_C")? PATH_C: sys_get_temp_dir();
|
||||
|
||||
require_once PATH_CONTROLLERS . $class . '.php';
|
||||
$sysConfig = \System::getSystemConfiguration();
|
||||
|
||||
if (is_callable(array($class, $action))) {
|
||||
$controller = new $class();
|
||||
$controller->setHttpRequestData($_REQUEST);
|
||||
$controller->call($action);
|
||||
} else {
|
||||
header('location: /errors/error404?url=' . urlencode($this->requestUri));
|
||||
}*/
|
||||
\Luracast\Restler\Defaults::$cacheDirectory = $cacheDir;
|
||||
$productionMode = !(isset($sysConfig["service_api_debug"]) && $sysConfig["service_api_debug"]);
|
||||
|
||||
Util\Logger::log("Serving API mode: " . ($productionMode? "production": "development"));
|
||||
|
||||
// create a new Restler instance
|
||||
//$rest = new \Luracast\Restler\Restler();
|
||||
$rest = new \Maveriks\Extension\Restler($productionMode);
|
||||
$rest->setworkspace($workspace);
|
||||
|
||||
// setting api version to Restler
|
||||
$rest->setAPIVersion('1.0');
|
||||
// adding $authenticationClass to Restler
|
||||
|
||||
// Setting database connection source
|
||||
list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');
|
||||
$port = empty($port) ? '' : ";port=$port";
|
||||
Services\OAuth2\Server::setDatabaseSource(DB_USER, DB_PASS, DB_ADAPTER.":host=$host;dbname=".DB_NAME.$port);
|
||||
|
||||
// Setting default OAuth Client id, for local PM Web Designer
|
||||
Services\OAuth2\Server::setPmClientId($pmOauthClientId);
|
||||
Services\OAuth2\Server::setWorkspace($workspace);
|
||||
|
||||
$rest->setOverridingFormats('JsonFormat', 'UploadFormat');
|
||||
|
||||
$rest->addAPIClass('\ProcessMaker\\Services\\OAuth2\\Server', 'oauth2');
|
||||
$rest->handle();
|
||||
|
||||
} else {
|
||||
return self::RUNNING_WORKFLOW;
|
||||
@@ -244,7 +257,7 @@ class WebApplication
|
||||
*/
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
|
||||
$_SERVER['REQUEST_URI'] = $uri;
|
||||
$_SERVER['REQUEST_URI'] = $uri;
|
||||
|
||||
$this->rest->inputExecute = $inputExecute;
|
||||
$this->rest->handle();
|
||||
@@ -269,6 +282,8 @@ class WebApplication
|
||||
$apiIniFile = $servicesDir . DS . 'api.ini';
|
||||
// $authenticationClass - contains the class name that validate the authentication for Restler
|
||||
$authenticationClass = 'ProcessMaker\\Services\\OAuth2\\Server';
|
||||
// $pmOauthClientId - contains PM Local OAuth Id (Web Designer)
|
||||
$pmOauthClientId = 'x-pm-local-client';
|
||||
|
||||
/*
|
||||
* Load Api ini file for Rest Service
|
||||
@@ -292,9 +307,37 @@ class WebApplication
|
||||
}
|
||||
}
|
||||
|
||||
$this->configureRest(SYS_SYS, $version, $multipart);
|
||||
// Setting current workspace to Api class
|
||||
Services\Api::setWorkspace(SYS_SYS);
|
||||
$cacheDir = defined("PATH_C")? PATH_C: sys_get_temp_dir();
|
||||
|
||||
$sysConfig = \System::getSystemConfiguration();
|
||||
|
||||
\Luracast\Restler\Defaults::$cacheDirectory = $cacheDir;
|
||||
$productionMode = (bool) !(isset($sysConfig["service_api_debug"]) && $sysConfig["service_api_debug"]);
|
||||
|
||||
Util\Logger::log("Serving API mode: " . ($productionMode? "production": "development"));
|
||||
|
||||
// create a new Restler instance
|
||||
//$rest = new \Luracast\Restler\Restler();
|
||||
$this->rest = new \Maveriks\Extension\Restler($productionMode);
|
||||
// setting flag for multipart to Restler
|
||||
$this->rest->setFlagMultipart($multipart);
|
||||
// setting api version to Restler
|
||||
$this->rest->setAPIVersion($version);
|
||||
// adding $authenticationClass to Restler
|
||||
$this->rest->addAuthenticationClass($authenticationClass, '');
|
||||
|
||||
// Setting database connection source
|
||||
list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');
|
||||
$port = empty($port) ? '' : ";port=$port";
|
||||
Services\OAuth2\Server::setDatabaseSource(DB_USER, DB_PASS, DB_ADAPTER.":host=$host;dbname=".DB_NAME.$port);
|
||||
|
||||
// Setting default OAuth Client id, for local PM Web Designer
|
||||
Services\OAuth2\Server::setPmClientId($pmOauthClientId);
|
||||
|
||||
$this->rest->setOverridingFormats('JsonFormat', 'UploadFormat');
|
||||
|
||||
$isPluginRequest = strpos($uri, '/plugin-') !== false ? true : false;
|
||||
|
||||
if ($isPluginRequest) {
|
||||
@@ -319,7 +362,7 @@ class WebApplication
|
||||
$namespace = strpos($namespace, "//") === false? $namespace: str_replace("//", '', $namespace);
|
||||
|
||||
//if (! class_exists($namespace)) {
|
||||
require_once $classFile;
|
||||
require_once $classFile;
|
||||
//}
|
||||
|
||||
$this->rest->addAPIClass($namespace);
|
||||
@@ -352,44 +395,6 @@ class WebApplication
|
||||
}
|
||||
}
|
||||
|
||||
public function configureRest($workspace, $version, $multipart = false)
|
||||
{
|
||||
// $pmOauthClientId - contains PM Local OAuth Id (Web Designer)
|
||||
$pmOauthClientId = 'x-pm-local-client';
|
||||
|
||||
// Setting current workspace to Api class
|
||||
Services\Api::setWorkspace($workspace);
|
||||
$cacheDir = defined("PATH_C")? PATH_C: sys_get_temp_dir();
|
||||
|
||||
$sysConfig = \System::getSystemConfiguration();
|
||||
|
||||
\Luracast\Restler\Defaults::$cacheDirectory = $cacheDir;
|
||||
$productionMode = false; //(bool) !(isset($sysConfig["service_api_debug"]) && $sysConfig["service_api_debug"]);
|
||||
|
||||
Util\Logger::log("Serving API mode: " . ($productionMode? "production": "development"));
|
||||
|
||||
// create a new Restler instance
|
||||
//$rest = new \Luracast\Restler\Restler();
|
||||
$this->rest = new \Maveriks\Extension\Restler($productionMode);
|
||||
$this->rest->setworkspace($workspace);
|
||||
// setting flag for multipart to Restler
|
||||
$this->rest->setFlagMultipart($multipart);
|
||||
// setting api version to Restler
|
||||
$this->rest->setAPIVersion($version);
|
||||
// adding $authenticationClass to Restler
|
||||
|
||||
// Setting database connection source
|
||||
list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');
|
||||
$port = empty($port) ? '' : ";port=$port";
|
||||
Services\OAuth2\Server::setDatabaseSource(DB_USER, DB_PASS, DB_ADAPTER.":host=$host;dbname=".DB_NAME.$port);
|
||||
|
||||
// Setting default OAuth Client id, for local PM Web Designer
|
||||
Services\OAuth2\Server::setPmClientId($pmOauthClientId);
|
||||
Services\OAuth2\Server::setWorkspace($workspace);
|
||||
|
||||
$this->rest->setOverridingFormats('JsonFormat', 'UploadFormat');
|
||||
}
|
||||
|
||||
public function parseApiRequestUri()
|
||||
{
|
||||
$url = explode("/", $this->requestUri);
|
||||
@@ -574,4 +579,4 @@ class WebApplication
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user