Skip to content

Commit

Permalink
支持华为云函数
Browse files Browse the repository at this point in the history
  • Loading branch information
luolongfei committed May 15, 2022
1 parent 2de123a commit 201616f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,35 @@ function handler($event, $context)
return run();
}

/**
* 华为云函数
*
* @param $event
* @param $context
*
* @return bool|string
*/
function huawei_handler($event, $context)
{
$logger = $context->getLogger();

$logger->info('开始执行华为云函数');

// 手动设置环境变量
$logger->info('设置环境变量');
$allEnvKeys = array_keys((array)env());
foreach ($allEnvKeys as $key) {
$value = $context->getUserData((string)$key);
if (strlen($value) > 0) {
$logger->info('从控制台发现环境变量:' . $key);
putenv("{$key}={$value}");
}
}
$logger->info('环境变量设置完成');

return run();
}

/**
* @return string|bool
*/
Expand Down
29 changes: 29 additions & 0 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,35 @@ function handler($event, $context)
return run();
}

/**
* 华为云函数
*
* @param $event
* @param $context
*
* @return bool|string
*/
function huawei_handler($event, $context)
{
$logger = $context->getLogger();

$logger->info('开始执行华为云函数');

// 手动设置环境变量
$logger->info('设置环境变量');
$allEnvKeys = array_keys((array)env());
foreach ($allEnvKeys as $key) {
$value = $context->getUserData((string)$key);
if (strlen($value) > 0) {
$logger->info('从控制台发现环境变量:' . $key);
putenv("{$key}={$value}");
}
}
$logger->info('环境变量设置完成');

return run();
}

/**
* @return string|bool
*/
Expand Down

0 comments on commit 201616f

Please sign in to comment.