非常高兴地宣布,我和Tom终于推出了PHP GitHub Sponsors,一个用于PHP与GitHub Sponsors GraphQL API交互的包。
目前,PHP GitHub Sponsors允许您进行基于ACL的检查,以查看一个GitHub账户是否在赞助另一个账户。虽然该包与框架无关,因此可以在任何PHP应用程序中使用,但它还提供了对Laravel框架的集成。
以下是使用示例。首先,在您的.env
文件中设置个人访问令牌
GH_SPONSORS_TOKEN=ghp_xxx
此访问令牌应具有user:read
和organization:read
范围。
然后,您可以开始使用此包
use GitHub\Sponsors\Facades\GitHubSponsors;
// Check if driesvints is being sponsored by nunomaduro...
GitHubSponsors::login('driesvints')->isSponsoredBy('nunomaduro');
// Check if the blade-ui-kit organization is sponsored by nunomaduro...
GitHubSponsors::login('nunomaduro')->isSponsoring('blade-ui-kit');
// Check if the authenticated user is sponsored by Gummibeer...
GitHubSponsors::viewer()->isSponsoredBy('Gummibeer');
// Check if the authenticated user is sponsoring driesvints...
GitHubSponsors::viewer()->isSponsoring('driesvints');
您还可以从IoC容器中检索客户端并对其进行调用
use GitHub\Sponsors\Client;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::get('/home', function (Request $request, Client $sponsors) {
$isSponsoring = $sponsors->viewer()->isSponsoredBy(
$request->get('github_username')
);
if ($isSponsoring) {
return redirect('/secret-homepage');
}
return view('welcome');
});
可赞助
此外,您可以将GitHub\Sponsors\Concerns\Sponsorable
特性添加到Eloquent模型,例如User
模型,以使其可赞助
use GitHub\Sponsors\Concerns\Sponsorable;
use GitHub\Sponsors\Contracts\Sponsorable as SponsorableContract;
use Illuminate\Database\Eloquent\Model;
class User extends Model implements SponsorableContract
{
use Sponsorable;
}
然后,用户将使用其github
列的值作为其用户名。用户还可以在github_token
列中添加他们的个人访问令牌,以让他们检查他们的私人赞助。
现在,您可以像这样使用该模型
$user = User::where('github', 'driesvints')->first();
// Check if driesvints is being sponsored by nunomaduro...
$user->isSponsoredBy('nunomaduro');
// Check if driesvints is sponsoring nunomaduro...
$user->isSponsoring('driesvints');
有关使用方法和详细信息,请参阅文档。
路线图
最初,我想在包中提供更多功能。但由于我只能在过去几个月间零零散散地工作,感觉进展不够快。因此,我决定提前发布,提供一个最小功能集,并继续在公开场合对其进行开发。
我们想在包中实现很多计划。以下是我们的路线图上的一些功能
结论
这个包不可能没有一些杰出的人。我真的很想感谢 Claudio Dekker 在开发包期间提供的所有反馈和帮助。我还想感谢 Sarah Vessels 提供的GitHub GraphQL API反馈。最后,我想感谢 Tom Witkowski 作为共同维护者加入我,并帮助开发和改进这个包。
我希望你会喜欢这个,如果你最终使用了这个包,请一定在 Twitter上告诉我。祝您享受!
opi, joedixon, alexanderfalkenberg 喜欢这篇文章