simialbi / yii2-firebasemailer
A PHP-client-library for using firebase component to send push notifications.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=8.2
- kreait/firebase-php: ^7.16.1
- yiisoft/yii2: ^2.0.20
Requires (Dev)
This package is auto-updated.
Last update: 2025-02-13 15:54:07 UTC
README
A lightweight PHP-client-library for using Firebase push notification services with yii2 framework. Reduces the complexity of network-communication between client and SMS gateway, to help save time and money for focusing on their business logic.
Installation
The preferred way to install this extension is through composer.
Either run
$ php composer.phar require --prefer-dist simialbi/yii2-firebasemailer
or add
"simialbi/yii2-firebasemailer": "^1.0.0"
to the require
section of your composer.json
.
Usage
In order to use this component, you will need to:
- Setup component your application so that the module is available.
Setup component
return [ // [...] 'components' => [ 'firebase' => [ 'class' => 'simialbi\yii2\firebasemailer\Mailer', 'firebaseCredentials' => [ 'type' => 'service_account', 'project_id' => 'my_app', 'private_key_id' => '4d95db2814a6e057611f7883a9a243f6', 'private_key' => '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n', 'client_email' => 'firebase-adminsdk-fbsvc@my_app.iam.gserviceaccount.com', 'client_id' => '000000000000000000001', 'auth_uri' => 'https://accounts.google.com/o/oauth2/auth', 'token_uri' => 'https://oauth2.googleapis.com/token', 'auth_provider_x509_cert_url' => 'https://www.googleapis.com/oauth2/v1/certs', 'client_x509_cert_url' => 'https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fbsvc%40my_app.iam.gserviceaccount.com', 'universe_domain' => 'googleapis.com' ] ] ] ];
Example Usage
To send a message create a new Message
instance and set at least the content and recipients.
<?php /** @var \simialbi\yii2\firebasemailer\Mailer $firebase */ $firebase = Yii::$app->get('firebase', true); $message = $firebase->createMessage(); $message ->setSubject('My subject') ->setTextBody('My body\nGreetings') ->setData([ 'viewToOpen' => 'my_action', 'actionId' => 123 ]) ->to(['topic' => 'my_topic']) ->to(['myFirstT0ken', 'my2ndT0ken']) // alternative ; if ($message->send()) { echo 'success'; } else { echo 'failure'; }
License
yii2-firebasmailer is released under MIT license. See bundled LICENSE for details.