add curl hook

This commit is contained in:
crazywhalecc 2023-03-15 20:54:33 +08:00
parent 5d347adbcf
commit 3488bce63d
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace SPC\store;
class CurlHook
{
/**
* 执行 GitHub Token Curl 头添加
*
* @param string $method 修改的 method
* @param string $url 修改的链接
* @param array $headers 修改的 headers
*/
public static function setupGithubToken(string &$method, string &$url, array &$headers): void
{
if (!getenv('GITHUB_TOKEN')) {
return;
}
if (getenv('GITHUB_USER')) {
$auth = base64_encode(getenv('GITHUB_USER') . ':' . getenv('GITHUB_TOKEN'));
$headers[] = "Authorization: Basic {$auth}";
logger()->info("using basic github token for {$method} {$url}");
} else {
$auth = getenv('GITHUB_TOKEN');
$headers[] = "Authorization: Bearer {$auth}";
logger()->info("using bearer github token for {$method} {$url}");
}
}
}