fcorz/hyperf-firebase

Hyperf 的 Firebase PHP Admin SDK 包

v2.0.0 2024-02-01 07:13 UTC

This package is auto-updated.

Last update: 2024-09-30 09:14:06 UTC


README

一个为 Firebase PHP Admin SDK 定制的 Hyperf 包。

安装

composer require fcorz/hyperf-firebase

发布

php bin/hyperf.php vendor:publish fcorz/hyperf-firebase

配置

使用 JSON 文件存储凭据

FIREBASE_CREDENTIALS=config/certificates/service-account-file.json

使用方法

外观

use Fcorz\Hyperf\Firebase\Facades\Firebase;

// Return an instance of the Messaging component for the default Firebase project
$defaultMessaging = Firebase::messaging();

// Return an instance of the Auth component for a specific Firebase project
$appMessaging = Firebase::project('app')->messaging();

$anotherAppMessaging = Firebase::project('another-app')->messaging();

// send message
$message = [
    'token' => $deviceToken,
    'notification' => [/* Notification data as array */], // optional
    'data' => [/* data array */], // optional
];

Firebase::messaging()->send($message);

依赖注入

use Fcorz\Hyperf\Firebase\ApplicationProxy;

class yourProjectFirebase extends ApplicationProxy
{
    protected string $name = 'project_name';

}

// send message
class yourClass
{
    public function __construct(yourProjectFirebase $firebase)
    {
        $firebase->messaging()->send($message);
    }
}

Firebase Admin PHP SDK 的未来

请阅读有关 Firebase Admin PHP SDK 未来的信息,请访问 SDK 的 GitHub 仓库