prusaktech/lumen-firebase

基于Kreait Firebase的Lumen包,用于Firebase PHP Admin SDK

1.2.1 2019-12-27 11:14 UTC

This package is not auto-updated.

Last update: 2024-09-29 08:23:40 UTC


README

这是一个用于Firebase PHP Admin SDK的Lumen包。

Current version Firebase Admin SDK version Supported Lumen versions

安装

此包需要Lumen 6.x及以上版本。

composer require prusak-tech/lumen-firebase

bootstrap/app.php中添加以下服务提供者

// bootstrap/app.php
<?php

/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/

// ...

$app->register(\PrusakTech\Lumen\Firebase\ServiceProvider::class);

// ...

配置

为了使用服务器SDK访问Firebase项目及其相关服务,请求必须经过认证。对于服务器之间的通信,这通过服务账户完成。

该包使用自动发现来通过检查某些环境变量并查看Google的已知路径来查找用于认证Firebase API请求所需的凭据。

如果您尚未生成服务账户,可以按照官方文档页面中的说明进行操作:https://firebase.google.com/docs/admin/setup#initialize_the_sdk

下载服务账户JSON文件后,您可以通过在.env文件中指定环境变量FIREBASE_CREDENTIALS来配置该包

FIREBASE_CREDENTIALS=/full/path/to/firebase_credentials.json
# or
FIREBASE_CREDENTIALS=relative/path/to/firebase_credentials.json

有关进一步配置,请参阅config/firebase.php。您需要手动复制,因为在Lumen中是这样做的。

使用

获取组件后,请参阅Firebase PHP Admin SDK文档以获取有关如何使用的更多信息。

您不需要也不应使用SDK文档中描述的new Factory()模式,这已经通过Laravel服务提供者为您完成。请使用依赖注入、Facades或app()辅助函数。

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件