2019-12-30 14:15:35 +00:00
|
|
|
<?php
|
2020-06-07 10:43:47 +00:00
|
|
|
error_reporting(E_ALL & ~E_NOTICE);
|
2020-01-18 12:12:21 +00:00
|
|
|
include 'vendor/autoload.php';
|
2019-12-30 14:15:35 +00:00
|
|
|
include 'conststr.php';
|
2020-04-01 10:44:50 +00:00
|
|
|
include 'common.php';
|
2019-12-30 14:15:35 +00:00
|
|
|
|
2020-01-18 12:12:21 +00:00
|
|
|
//echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
|
2020-03-13 12:35:28 +00:00
|
|
|
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
|
2020-08-06 02:46:11 +00:00
|
|
|
if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/TencentSCF_file.php';
|
|
|
|
else include 'platform/TencentSCF_env.php';
|
2020-06-07 10:43:47 +00:00
|
|
|
} elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
|
|
|
|
include 'platform/AliyunFC.php';
|
2020-07-13 09:36:17 +00:00
|
|
|
} elseif ($_SERVER['_APP_SHARE_DIR']=='/var/share/CFF/processrouter') {
|
2020-08-08 03:19:10 +00:00
|
|
|
//if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/HuaweiFG_file.php';
|
|
|
|
//else include 'platform/HuaweiFG_env.php';
|
|
|
|
echo 'FG' . PHP_EOL;
|
2020-08-16 03:40:42 +00:00
|
|
|
} elseif ($_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') {
|
|
|
|
//set_include_path(get_include_path() . PATH_SEPARATOR . '/opt/php');
|
|
|
|
//include 'BaiduBce.phar';
|
|
|
|
include 'platform/BaiduCFC.php';
|
2020-03-13 12:35:28 +00:00
|
|
|
} elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') {
|
2020-06-07 10:43:47 +00:00
|
|
|
include 'platform/Heroku.php';
|
2020-01-18 12:12:21 +00:00
|
|
|
$path = getpath();
|
|
|
|
//echo 'path:'. $path;
|
|
|
|
$_GET = getGET();
|
|
|
|
//echo '<pre>'. json_encode($_GET, JSON_PRETTY_PRINT).'</pre>';
|
|
|
|
$re = main($path);
|
|
|
|
$sendHeaders = array();
|
|
|
|
foreach ($re['headers'] as $headerName => $headerVal) {
|
|
|
|
header($headerName . ': ' . $headerVal, true);
|
|
|
|
}
|
|
|
|
http_response_code($re['statusCode']);
|
|
|
|
echo $re['body'];
|
|
|
|
} else {
|
2020-06-07 10:43:47 +00:00
|
|
|
include 'platform/Normal.php';
|
2020-01-18 12:12:21 +00:00
|
|
|
$path = getpath();
|
|
|
|
//echo 'path:'. $path;
|
|
|
|
$_GET = getGET();
|
|
|
|
//echo '<pre>'. json_encode($_GET, JSON_PRETTY_PRINT).'</pre>';
|
2019-12-30 14:15:35 +00:00
|
|
|
|
2020-01-18 12:12:21 +00:00
|
|
|
$re = main($path);
|
|
|
|
$sendHeaders = array();
|
|
|
|
foreach ($re['headers'] as $headerName => $headerVal) {
|
|
|
|
header($headerName . ': ' . $headerVal, true);
|
2019-12-30 14:15:35 +00:00
|
|
|
}
|
2020-01-18 12:12:21 +00:00
|
|
|
http_response_code($re['statusCode']);
|
|
|
|
echo $re['body'];
|
|
|
|
}
|
|
|
|
|
2020-06-07 10:43:47 +00:00
|
|
|
// Tencent SCF
|
2020-01-18 12:12:21 +00:00
|
|
|
function main_handler($event, $context)
|
|
|
|
{
|
|
|
|
$event = json_decode(json_encode($event), true);
|
|
|
|
$context = json_decode(json_encode($context), true);
|
|
|
|
printInput($event, $context);
|
|
|
|
unset($_POST);
|
|
|
|
unset($_GET);
|
|
|
|
unset($_COOKIE);
|
|
|
|
unset($_SERVER);
|
|
|
|
GetGlobalVariable($event);
|
2020-01-20 04:49:55 +00:00
|
|
|
//echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>';
|
2020-01-18 12:12:21 +00:00
|
|
|
$path = GetPathSetting($event, $context);
|
2020-02-20 03:59:58 +00:00
|
|
|
|
2020-01-18 12:12:21 +00:00
|
|
|
return main($path);
|
|
|
|
}
|
2020-06-07 10:43:47 +00:00
|
|
|
|
2020-08-16 03:40:42 +00:00
|
|
|
// Aliyun FC & Huawei FG & Baidu CFC
|
2020-07-13 09:36:17 +00:00
|
|
|
function handler($event, $context)
|
2020-06-07 10:43:47 +00:00
|
|
|
{
|
2020-07-13 09:36:17 +00:00
|
|
|
if (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
|
|
|
|
// Aliyun FC
|
|
|
|
set_error_handler("myErrorHandler");
|
|
|
|
$tmp = array(
|
|
|
|
'method' => $event->getMethod(),
|
|
|
|
'clientIP' => $event->getAttribute("clientIP"),
|
2020-09-22 11:41:50 +00:00
|
|
|
'requestURI' => $event->getAttribute("requestURI"),
|
2020-07-13 09:36:17 +00:00
|
|
|
'path' => spurlencode($event->getAttribute("path"), '/'),
|
|
|
|
'queryString' => $event->getQueryParams(),
|
|
|
|
'headers' => $event->getHeaders(),
|
|
|
|
'body' => $event->getBody()->getContents(),
|
|
|
|
);
|
|
|
|
$event = $tmp;
|
|
|
|
$context = json_decode(json_encode($context), true);
|
|
|
|
printInput($event, $context);
|
|
|
|
unset($_POST);
|
|
|
|
unset($_GET);
|
|
|
|
unset($_COOKIE);
|
|
|
|
unset($_SERVER);
|
|
|
|
GetGlobalVariable($event);
|
|
|
|
$path = GetPathSetting($event, $context);
|
2020-06-07 10:43:47 +00:00
|
|
|
|
2020-07-13 09:36:17 +00:00
|
|
|
$re = main($path);
|
|
|
|
|
|
|
|
return new RingCentral\Psr7\Response($re['statusCode'], $re['headers'], $re['body']);
|
2020-06-07 10:43:47 +00:00
|
|
|
|
2020-07-13 09:36:17 +00:00
|
|
|
} elseif ($_SERVER['_APP_SHARE_DIR']=='/var/share/CFF/processrouter') {
|
|
|
|
// Huawei FG
|
|
|
|
global $contextUserData;
|
|
|
|
$contextUserData = $context;
|
2020-08-08 03:19:10 +00:00
|
|
|
if ($context->getUserData('ONEMANAGER_CONFIG_SAVE')=='file') include_once 'platform/HuaweiFG_file.php';
|
|
|
|
else include_once 'platform/HuaweiFG_env.php';
|
|
|
|
|
2020-07-13 09:36:17 +00:00
|
|
|
$event = json_decode(json_encode($event), true);
|
|
|
|
if ($event['isBase64Encoded']) $event['body'] = base64_decode($event['body']);
|
|
|
|
|
|
|
|
printInput($event, $context);
|
|
|
|
unset($_POST);
|
|
|
|
unset($_GET);
|
|
|
|
unset($_COOKIE);
|
|
|
|
unset($_SERVER);
|
|
|
|
GetGlobalVariable($event);
|
|
|
|
//echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>';
|
|
|
|
$path = GetPathSetting($event, $context);
|
|
|
|
|
|
|
|
return main($path);
|
2020-08-08 03:19:10 +00:00
|
|
|
|
2020-08-16 03:40:42 +00:00
|
|
|
} elseif ($_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') {
|
|
|
|
// Baidu CFC
|
|
|
|
//$html = '<pre>'. json_encode($event, JSON_PRETTY_PRINT).'</pre>';
|
|
|
|
//$html .= '<pre>'. json_encode($context, JSON_PRETTY_PRINT).'</pre>';
|
|
|
|
//$html .= '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
|
|
|
|
//$html .= $event['path'];
|
|
|
|
//$html .= $context['functionBrn'];
|
|
|
|
//return json_encode(output($html), JSON_FORCE_OBJECT);
|
|
|
|
|
|
|
|
printInput($event, $context);
|
|
|
|
unset($_POST);
|
|
|
|
unset($_GET);
|
|
|
|
unset($_COOKIE);
|
|
|
|
unset($_SERVER);
|
|
|
|
GetGlobalVariable($event);
|
|
|
|
//echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>';
|
|
|
|
$path = GetPathSetting($event, $context);
|
|
|
|
|
|
|
|
return json_encode(main($path), JSON_FORCE_OBJECT);
|
|
|
|
|
2020-07-13 09:36:17 +00:00
|
|
|
}
|
2020-06-07 10:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// used by Aliyun FC
|
|
|
|
function myErrorHandler($errno, $errstr, $errfile, $errline) {
|
|
|
|
if (!(error_reporting() & $errno)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch ($errno) {
|
|
|
|
case E_USER_ERROR:
|
|
|
|
$errInfo = array(
|
|
|
|
"errorMessage" => $errstr,
|
|
|
|
"errorType" => \ServerlessFC\friendly_error_type($errno),
|
|
|
|
"stackTrace" => array(
|
|
|
|
"file" => $errfile,
|
|
|
|
"line" => $errline,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: // E_USER_WARNING | E_USER_NOTICE
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|