fcorz / hyperf-firebase
A Hyperf package for the Firebase PHP Admin SDK
v2.0.0
2024-02-01 07:13 UTC
Requires
- php: >=7.4
- hyperf/cache: ~2.2.0
- hyperf/guzzle: ~2.2.0
- hyperf/logger: ~2.2.0
- hyperf/utils: ~2.2.0
- kreait/firebase-php: ^6.0
- symfony/cache: ^5.4|^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.0
- swoole/ide-helper: dev-master
README
A Hyperf package for the Firebase PHP Admin SDK.
Installation
composer require fcorz/hyperf-firebase
Publish
php bin/hyperf.php vendor:publish fcorz/hyperf-firebase
Configuration
Credentials with JSON files
FIREBASE_CREDENTIALS=config/certificates/service-account-file.json
Usage
Facades
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);
Dependency Injection
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); } }
The future of the Firebase Admin PHP SDK
Please read about the future of the Firebase Admin PHP SDK on the SDK's GitHub Repository.