kreait / firebase-bundle Goto Github PK
View Code? Open in Web Editor NEWA Symfony Bundle for the Firebase PHP Admin SDK
Home Page: https://github.com/kreait/firebase-php
License: MIT License
A Symfony Bundle for the Firebase PHP Admin SDK
Home Page: https://github.com/kreait/firebase-php
License: MIT License
Hello, When I try to send push notifications, I get errors:
Requested entity was not found
But I try to catch error, I have: In Parser.php line 95: The JWT string must have two dots
It is my code: (https://pastebin.com/xeZ4tbP9)
`public function sendPush(string $pushTitle, string $pushBody, User $user){
$serviceAccount = ServiceAccount::fromJsonFile($this->dir);
$firebase = (new Factory())
->withServiceAccount($serviceAccount)
->create();
if(null !== $user->getDeviceTokens()){
foreach ($user->getDeviceTokens() as $token){
try {
return $firebase->getAuth()->verifyIdToken($token->getToken());
} catch (IssuedInTheFuture $e) {
exit;
} catch (InvalidToken $e) {
echo $e->getMessage();
exit;
}
$messaging = $firebase->getMessaging();
$message = CloudMessage::fromArray([
'token' => $token->getToken(),
'notification' => [
'title' => $pushTitle,
'body' => $pushBody
]
]);
try{
$messaging->send($message);
}catch(\Kreait\Firebase\Exception\Messaging\NotFound $e){
dump('Error');
}
}
}
}`
I reshaped the token and the error was the same.
The most interesting thing is that a few days ago this code worked, I did not change anything, but errors appeared.
What am I doing wrong?
A sample usage as per readme, for example, $container->get('firebase')
triggers deprecations, as the main bundle got a lot of deprecations since version 4.33.
I did have installed the composer require firebase/token-generator
I think they have change the path for FirebaseTokenGenerator to Firebase\Token\TokenGenerator
, can you please update this on repo?
Auth/TokenGenerator.php
$this->generator = new \Services_FirebaseTokenGenerator($this->secret);
Attempted to load class "Services_FirebaseTokenGenerator" from the global namespace.
Did you forget a "use" statement?
kreait/firebase-php
and kreait/firebase-bundle
are you using?"kreait/firebase-bundle": "1.0"
kreait/firebase-php ^4.0
7.1.9
I setup the bundle as show in the readme
my config.yml is
kreait_firebase:
projects:
first:
public: true
# Optional: If set to true, this project is used when
# using Kreait\Firebase as a type hint for dependency injection
#default: true
credentials: '%kernel.root_dir%/config/model-firebase-adminsdk.json'
database_uri: 'https://model.firebaseio.com/'
alias: 'firebase'
The php I created more or less as done in the app:fcm:send-message
example ( https://github.com/jeromegamez/firebase-php-examples )
$messaging = $this->container->get('firebase')->getMessaging();
$message = $message->setTitle($message->getTitle())->setBody($message->getBody());
$responseData = $messaging->send($message);
But despite having indicated the path to the json in the config.yml, I'm receiving this error
Kreait\Firebase\ServiceAccount\Discovery\FromEnvironmentVariable: The environment variable "FIREBASE_CREDENTIALS" is not set.
Kreait\Firebase\ServiceAccount\Discovery\FromEnvironmentVariable: The environment variable "GOOGLE_APPLICATION_CREDENTIALS" is not set.
Kreait\Firebase\ServiceAccount\Discovery\FromGoogleWellKnownFile: The well known file is not readable or invalid
also, the doc, say that I could set default: true, but decommenting this line result in
InvalidConfigurationException
Unrecognized option "default" under "kreait_firebase.projects.first"
Cant use Firebase provided private key encoded with Symfony's new secret encryption system
I dont like to keep Firebase keys in json file. It would be much better to provide them in configuration file as encrypted env variables encoded with Symfony's secret management system. In config/packages/firebase.yaml
instead of credentials
value set to json file I tried to provide list of the values directly:
my_project:
default: true
public: true
credentials:
type: "service_account"
project_id: "my_project_id"
private_key_id: 'my_project_private_key_id'
private_key: 'my_project_private_key'
client_email: 'my_project_client_email'
client_id: 'my_project_client_id'
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: 'my_project_cert'
If values are set directly here - it works.
The next step would be to encode these vars ant provide them in bundles yaml file with '%env(MY_VAR)%'
.
But there is an issue with private_key
value. After I tried to send push notification this warning is received: Warning: openssl_sign(): supplied key param cannot be coerced into a private key.
As I understand the issue here is because of newline character \n
in this private key. Example: https://i.imgur.com/83eDkL8.png
But because it is used in yaml, I cant use str_replace to change them. Is there a way to use this key encoded?
When i calling the service kreait_firebase
or kreait_firebase.project_name
i get:
You have requested a non-existent service "kreait_firebase".
kreait/firebase-bundle 1.1.1
kreait/firebase-php 4.16.0
kreait/firebase-tokens 1.7.1
kreait/gcp-metadata 1.0.1
php 7.2.7
symfony 4.1.4
/**
* @Route("/test")
*/
public function test()
{
$firebase = $this->get('kreait_firebase');
$title = 'test title';
$body = 'test body';
$token = 'my_foo_token';
$notification = Notification::create($title, $body);
$message = CloudMessage::withTarget('token', $token);
$message->withNotification($notification);
dd($firebase->getMessaging()->send($message));
}
Hello,
Thanks for this bundle!
I was wondering, is there any way to authenticate a user with this current version?
Hello,
I've been learning PHP with Symfony for a few months and want to add Firebase to my project (which I'm learning !).
There are new issues with the last version of Symfony with bundles (https://stackoverflow.com/questions/44928982/appkernel-php-weird-behavior#comment76834486_44928982) and I cannot fix it for your bundle.
The installation of the bundle crashes my project and I cannot find the file FirebaseBundle.php which is referred to in the AppKernel.php.
I don't know if I'm clear enough but I'd love if you could help me out !
Thanks for your bundle and the sdk anyway ! :)
I am trying to do a simple push. The plugin is registred in the bundles.php
<?php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Kreait\Firebase\Symfony\Bundle\FirebaseBundle::class => ['all' => true],
];
I have created a service file called "PushService.php" with a send function in it.
<?php
namespace App\Service;
use Kreait\Firebase\Contract\Messaging;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
class PushService
{
public function __construct(Messaging $messaging)
{
$this->messaging = $messaging;
}
public function sendy(){
$deviceToken = '...'; // need to get this out of firebase
$message = CloudMessage::withTarget('token', $deviceToken)
->withNotification(Notification::create('Testtitel', 'Inhalt')) // optional
->withData(['key' => 'value']) // optional
;
$this->messaging->send($message);
}
}
I am calling the function from my PushController.php
<?php
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use App\Service\PushService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class PushConroller extends AbstractController{
#[Route('/testing/sendPush', name: 'test_sendPush')]
public function sendPushTest(PushService $pushService)
{
$pushService->sendy();
return new Response("test");
}
}
When i call the url /testing/sendPush i get the following error:
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/doctrine-bundle": "^2.8",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.14",
"google/cloud-text-to-speech": "^1.5",
"kreait/firebase-bundle": "^5.0",
"kreait/laravel-firebase": "^5.2",
"symfony/console": "6.2.*",
"symfony/dotenv": "6.2.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "6.2.*",
"symfony/maker-bundle": "^1.48",
"symfony/notifier": "6.2.*",
"symfony/runtime": "6.2.*",
"symfony/uid": "6.2.*",
"symfony/yaml": "6.2.*",
"sngrl/php-firebase-cloud-messaging": "dev-master"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"symfony/flex": true,
"symfony/runtime": true
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-php81": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "6.2.*"
}
}
}
composer 2.3.5 Composer package
composer-plugin-api 2.3.0 The Composer Plugin API
composer-runtime-api 2.2.2 The Composer Runtime API
ext-bcmath 8.1.13 The bcmath PHP extension
ext-bz2 8.1.13 The bz2 PHP extension
ext-calendar 8.1.13 The calendar PHP extension
ext-ctype 8.1.13 The ctype PHP extension
ext-curl 8.1.13 The curl PHP extension
ext-date 8.1.13 The date PHP extension
ext-dom 20031129 The dom PHP extension
ext-exif 8.1.13 The exif PHP extension
ext-fileinfo 8.1.13 The fileinfo PHP extension
ext-filter 8.1.13 The filter PHP extension
ext-ftp 8.1.13 The ftp PHP extension
ext-gd 8.1.13 The gd PHP extension
ext-gettext 8.1.13 The gettext PHP extension
ext-gmp 8.1.13 The gmp PHP extension
ext-hash 8.1.13 The hash PHP extension
ext-iconv 8.1.13 The iconv PHP extension
ext-imagick 3.6.0 The imagick PHP extension
ext-imap 8.1.13 The imap PHP extension
ext-intl 8.1.13 The intl PHP extension
ext-json 8.1.13 The json PHP extension
ext-ldap 8.1.13 The ldap PHP extension
ext-libxml 8.1.13 The libxml PHP extension
ext-mbstring 8.1.13 The mbstring PHP extension
ext-mysqli 8.1.13 The mysqli PHP extension
ext-mysqlnd 0 The mysqlnd PHP extension (actual version: mysqlnd 8.1.13)
ext-openssl 8.1.13 The openssl PHP extension
ext-pcntl 8.1.13 The pcntl PHP extension
ext-pcre 8.1.13 The pcre PHP extension
ext-pdo 8.1.13 The PDO PHP extension
ext-pdo_dblib 8.1.13 The pdo_dblib PHP extension
ext-pdo_mysql 8.1.13 The pdo_mysql PHP extension
ext-pdo_pgsql 8.1.13 The pdo_pgsql PHP extension
ext-pdo_sqlite 8.1.13 The pdo_sqlite PHP extension
ext-pgsql 8.1.13 The pgsql PHP extension
ext-phar 8.1.13 The Phar PHP extension
ext-posix 8.1.13 The posix PHP extension
ext-pspell 8.1.13 The pspell PHP extension
ext-readline 8.1.13 The readline PHP extension
ext-reflection 8.1.13 The Reflection PHP extension
ext-session 8.1.13 The session PHP extension
ext-shmop 8.1.13 The shmop PHP extension
ext-simplexml 8.1.13 The SimpleXML PHP extension
ext-soap 8.1.13 The soap PHP extension
ext-sockets 8.1.13 The sockets PHP extension
ext-sodium 8.1.13 The sodium PHP extension
ext-spl 8.1.13 The SPL PHP extension
ext-sqlite3 8.1.13 The sqlite3 PHP extension
ext-sysvmsg 8.1.13 The sysvmsg PHP extension
ext-sysvsem 8.1.13 The sysvsem PHP extension
ext-sysvshm 8.1.13 The sysvshm PHP extension
ext-tidy 8.1.13 The tidy PHP extension
ext-tokenizer 8.1.13 The tokenizer PHP extension
ext-xml 8.1.13 The xml PHP extension
ext-xmlreader 8.1.13 The xmlreader PHP extension
ext-xmlwriter 8.1.13 The xmlwriter PHP extension
ext-xsl 8.1.13 The xsl PHP extension
ext-yaml 2.2.2 The yaml PHP extension
ext-zip 1.19.5 The zip PHP extension
ext-zlib 8.1.13 The zlib PHP extension
lib-bz2 1.0.8 The bz2 library
lib-curl 7.68.0 The curl library
lib-curl-libssh 0.9.3 curl libssh version
lib-curl-openssl 1.1.1.6 curl OpenSSL version (1.1.1.6)
lib-curl-zlib 1.2.11 curl zlib version
lib-date-timelib 2021.17 date timelib version
lib-date-zoneinfo 2022.6 zoneinfo ("Olson") database for date
lib-fileinfo-libmagic 540 fileinfo libmagic version
lib-gd 2.0.35 The gd library
lib-gd-freetype 2.10.1 freetype version for gd
lib-gd-libjpeg 8.0 libjpeg version for gd
lib-gd-libpng 1.6.37 libpng version for gd
lib-gd-libxpm 3.4.11 libxpm version for gd
lib-gmp 6.2.0 The gmp library
lib-iconv 2.31 The iconv library
lib-icu 66.1 The ICU unicode and globalization support library
lib-icu-cldr 36.1 ICU CLDR project version
lib-icu-unicode 13.0.0 ICU unicode version
lib-imagick-imagemagick 6.9.10.23 The imagick-imagemagick library
lib-ldap-openldap 2.4.49 OpenLDAP version of ldap
lib-libsodium 1.0.18 The libsodium library
lib-libxml 2.9.10 libxml library version
lib-libxslt 1.1.34 The libxslt library
lib-libxslt-libxml 2.9.10 libxml version libxslt is compiled against
lib-mbstring-libmbfl 1.3.2 mbstring libmbfl version
lib-mbstring-oniguruma 6.9.4 mbstring oniguruma version
lib-openssl 1.1.1.6 OpenSSL 1.1.1f 31 Mar 2020
lib-pcre 10.39 The pcre library
lib-pcre-unicode 14.0.0 PCRE Unicode version support
lib-pdo_pgsql-libpq 12.9 libpq for pdo_pgsql
lib-pdo_sqlite-sqlite 3.31.1 The pdo_sqlite-sqlite library
lib-sqlite3-sqlite 3.31.1 The sqlite3-sqlite library
lib-yaml-libyaml 0.2.2 libyaml version of yaml
lib-zip-libzip 1.5.1 The zip-libzip library
lib-zlib 1.2.11 The zlib library
php 8.1.13 The PHP interpreter
php-64bit 8.1.13 The PHP interpreter, 64bit
php-ipv6 8.1.13 The PHP interpreter, with IPv6 support
# Insert the commands issued in the terminal if they are needed
# to reproduce the issue. Otherwise, delete this code block.
// Insert the PHP code to reproduce the issue. Please ensure that it is code that
// can be copy pasted to reproduce it.
![grafik](https://user-images.githubusercontent.com/131554145/233843028-ca1b9f85-0d38-4544-b641-dad6e4bf4a83.png)
No response
When I calling $this->container->get('firebase'), I get :
My config file :
// %kernel.project_dir%/config/firebase/firebase.yaml
kreait_firebase:
projects:
default:
public: true
default: true
credentials: '%kernel.project_dir%/config/packages/firebase/service_account_key.json'
database_uri: 'https://myproject.firebaseio.com/'
alias: 'firebase'
My Service Account credentials file :
// %kernel.project_dir%/config/firebase/service_account_key.json
{
"type": "service_account",
"project_id": "............",
"private_key_id": "...........",
"private_key": "...........",
"client_email": "...........",
"client_id": "...........",
"auth_uri": "...........",
"token_uri": "...........",
"auth_provider_x509_cert_url": "...........",
"client_x509_cert_url": "..........."
}
Thk's
In a local project I have 2.6.0 installed combined with symfony/symfony 4.4.35. It apparently makes an incorrect call to Alias->setDeprecated()
(it takes 2 parameters, but 3 are provided with the template being the last one).
See run of cache:clear below.
php -v
): 7.4.22composer show | grep kreait
):vagrant@development:/vagrant$ php7.4 /vagrant/app/console cache:clear --env=dev --no-warmup -vvv
In Alias.php line 107:
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The deprecation template must contain the "%alias_id%" placeholder.
Exception trace:
at /vagrant/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Alias.php:107
Symfony\Component\DependencyInjection\Alias->setDeprecated() at /vagrant/vendor/kreait/firebase-bundle/src/DependencyInjection/FirebaseExtension.php:87
Kreait\Firebase\Symfony\Bundle\DependencyInjection\FirebaseExtension->registerService() at /vagrant/vendor/kreait/firebase-bundle/src/DependencyInjection/FirebaseExtension.php:42
Kreait\Firebase\Symfony\Bundle\DependencyInjection\FirebaseExtension->processProjectConfiguration() at /vagrant/vendor/kreait/firebase-bundle/src/DependencyInjection/FirebaseExtension.php:36
Kreait\Firebase\Symfony\Bundle\DependencyInjection\FirebaseExtension->load() at /vagrant/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php:76
Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass->process() at /vagrant/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php:39
Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass->process() at /vagrant/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:94
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /vagrant/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:762
Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /vagrant/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:596
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /vagrant/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:136
Symfony\Component\HttpKernel\Kernel->boot() at /vagrant/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:169
Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() at /vagrant/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:75
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /vagrant/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:149
Symfony\Component\Console\Application->run() at /vagrant/app/console:72
N/A. AFAICS this should happen in all Symfony 4.4 projects.
Hi there,
I'm getting this error, when i apply composer dump-autoload -o --no-dev
or composer dump-autoload --classmap-authoritative --no-dev
during the build of my container and i run it but when i apply composer dump-autoload -o
it works perfectly.
I only use cloud messaging service.
Thanks.
NOTICE: PHP message: PHP Fatal error: Failed to load class Google\Cloud\Firestore\FirestoreClient used by typed property Kreait\Firebase\Firestore::$client during preloading in Unknown on line 0
When I try to inject Auth from Kreait\Firebase\Contract\Auth an error shows:
Cannot autowire service "App\Service\FirebaseService": argument "$auth" of method "__construct()" references interface "Kreait\Firebase\Contract\Auth" but no such service exists. Did you create a class that implements this interface?
php -v
): 8.0.14composer show | grep kreait
):kreait/firebase-bundle 4.0.0 Symfony Bundle for the Firebase Admin SDK
kreait/firebase-php 6.2.0 Firebase Admin SDK
kreait/firebase-tokens 2.2.0 A library to work with Firebase tokens
I just follow the instructions below
<?php
namespace App\Service;
use Kreait\Firebase\Auth\UserRecord;
use Kreait\Firebase\Contract\Auth;
use Kreait\Firebase\Exception\Auth\FailedToVerifyToken;
use Kreait\Firebase\Exception\AuthException;
use Kreait\Firebase\Exception\FirebaseException;
class FirebaseService
{
private Auth $auth;
public function __construct(Auth $auth) {
$this->auth = $auth;
}
/**
* @throws FirebaseException
* @throws AuthException
*/
public function verifyIdToken(string $idToken): UserRecord
{
try {
$verifiedIdToken = $this->auth->verifyIdToken($idToken);
} catch (FailedToVerifyToken $e) {
echo 'The token is invalid: '.$e->getMessage();
}
$uid = $verifiedIdToken->claims()->get('sub');
$user = $this->auth->getUser($uid);
return $user;
}
}
When using messaging component's sendAll()
method to attempt sending multiple messages at once, if at least one of those messages bounces or there's an issue with FCM token, then the returned MulticastSendReport
object is always empty.
In case there are no issues with any of sub-requests, the returned MulticastSendReport
object contains all the feedback correctly.
Hi,
When i want to install this bundle i got this errors
Thanks in advance for your help
Problem 1
- kreait/firebase-bundle 1.6.1 requires symfony/dependency-injection ^2.8.50|^3.4.26|^4.1.12 -> no matching package found.
- kreait/firebase-bundle 1.6.0 requires symfony/dependency-injection ^2.8|^3.4|^4.0 -> no matching package found.
- Installation request for kreait/firebase-bundle ^1.6 -> satisfiable by kreait/firebase-bundle[1.6.0, 1.6.1].
Potential causes:
Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.
Hi. It seems that FCM localization is not supported by this library.
I'm referring to the parameters body_loc_key, body_loc_args, title_loc_key, title_loc_args.
Are you going to add support for this?
Thanks
Hello,
Could you add the possibility yo use a proxy ?
Maybe add a http client config in the bundle configuration ?
Do you already have a solution ?
Ty
hello how should i use these different accounts, i want to use a few different accounts
for example: kreait_firebase.my_project.messaging
kreait_firebase.other1.messaging
kreait_firebase.other2.messaging
I see you don't support Symfony 6.1 version. I get this when I run
composer require kreait/firebase-bundle
Problem 1
- google/cloud-core[v1.42.0, ..., v1.42.2] require guzzlehttp/psr7 ^1.2 -> found guzzlehttp/psr7[1.2.0, ..., 1.9.0] but the package is fixed to 2.4.1 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
- google/cloud-core[v1.43.0, ..., v1.47.2] require monolog/monolog ^1.1|^2.0 -> found monolog/monolog[1.1.0, ..., 1.27.1, 2.0.0, ..., 2.8.0] but the package is fixed to 3.2.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
- kreait/firebase-bundle 4.1.0 requires kreait/firebase-php ^6.0 -> satisfiable by kreait/firebase-php[6.0.0, ..., 6.9.1].
- kreait/firebase-php[6.3.0, ..., 6.9.1] require google/cloud-core ^1.44.2 -> satisfiable by google/cloud-core[v1.44.2, ..., v1.47.2].
- kreait/firebase-php[6.0.0, ..., 6.2.0] require google/cloud-core ^1.42.2 -> satisfiable by google/cloud-core[v1.42.2, ..., v1.47.2].
- Root composer.json requires kreait/firebase-bundle ^4.1 -> satisfiable by kreait/firebase-bundle[4.1.0].
Would you have any idea why FirebaseException which is just an extension of Exception wouldn't be caught in a regular try/catch?
About 1 out of 10 times I get a timeout to Firebase on this code:
protected function updateFirebase($file_no, $line_no)
{
echo "*updating firebase *\n";
try {
/** @var Firebase $firebase */
$firebase = $this->firebase;
$event = $firebase->getReference('dataprocessing');
if ($file_no == 0) {
$msg = "Processing finished";
} else {
$ttl = 10000 * 5;
$prior = ($file_no - 1) * 10000;
$current = round(100 * ($prior + $line_no) / $ttl);
$msg = "Processing " . $current . "%";
}
$event->set([$msg]);
} catch (Exception $objExc) {
$this->logger->info('Error on Firebase ' . $objExc->getMessage() . ' ' . __CLASS__ . "." . __FUNCTION__);
}
}
However when the timeout occurs, it always breaks and halts the program:
*updating firebase *
[Kreait\Firebase\Exception\FirebaseException]
HTTP Error: An error occurred when fetching the URI "https://mytestaccount.firebaseio.com/point2.json" with the adapter "guzzle_http" ("cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received").
[Ivory\HttpAdapter\HttpAdapterException]
An error occurred when fetching the URI "https://mytestaccount.firebaseio.com/point2.json" with the adapter "guzzle_http" ("cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received").
Trying to figure out what about this library would ignore the error trap.
Installed the bundle (version 1.2) using composer. Added the bundle to the AppKernel.php and pushed the commit to GitHub. My build is failing due to the following error:
[Symfony\Component\DependencyInjection\Exception\RuntimeException]
The definition for "kreait\firebase\factory" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an a
bstract definition solely used by child definitions, please add abstract=true, otherwise specify a class to get rid of this error.
Tried to set up the bundle with the project, by registering it in AppKernel.php, which is one of the initial steps and it is failing at that point.
Inside app/AppKernel.php
// ...
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = array(
// ...
new Kreait\Firebase\Symfony\Bundle\FirebaseBundle()
);
// ...
}
}
Hi,
I wanted to ask you a question for logic... Should I save the generated token in the db and set the expiry 99999days.. so we I can use same generated token again and again. Or this is bad consideration and I should generate new token on each new login in symfony?
Right now I have new token generated on each login, but I was thinking to save it in db and just use that rather then keep generating again and again.
Hi i'm trying to use in service but it seemce i get issue :
[EA] New value type (\Kreait\Firebase\Messaging\CloudMessage) is not matching the resolved parameter type and might introduce types-related false-positives.
it das not send any think.
note : that the same code working perfect in controller but not as service.
thank for help.
use Kreait\Firebase\Messaging;
use Kreait\Firebase\Messaging\AndroidConfig;
use Kreait\Firebase\Messaging\ApnsConfig;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
$message = CloudMessage::new()
->withNotification($notification)
->withDefaultSounds() // Enables default notifications sounds on iOS and Android devices.
->withApnsConfig(
ApnsConfig::new()
->withSound('raw/notif.mp3')
->withBadge(1)
)
->withData($msg);
Hi,
we're starting to use your bundle (and great lib) for push notifications. In our situation our backend service lives in project A and the apps live in project B. We run within GCP so our workloads have a service account for project A available. This service account has been given the roles for FCM in project B. It can send notifications when testing locally (with SA key file for project A but changing the project to B manually in the file). However, when we deploy the service account that is automatically provided will resolve to project A, not B. Meaning it cannot send messages. Ideally, it would be possible to simply override with an extra config entry field:
kreait_firebase:
projects:
some-project-name:
project_id: project-b
In the base library this seems possible by calling ::withProjectId(...)
, so right now I am leaning to use the library directly and write a new factory. But of course, being able to do this with the bundle is more appropriate.
Is there something I am missing or is it indeed a usecase that is not supported yet? If it is not supported would a PR be welcome?
Hi there,
is there any way to modify the underlaying guzzle client's options like eg. to add a guzzle retry middleware?
It would be nice if, as the symfony mailer, an event would be dispatched just before a notification was send to allow to alter the message in a large scale.
For example, today I have notifications sent to a flutter app. Flutter apps need a custom "data" to proper handle it :
Notification is delivered to system tray. When the user clicks on it to open app onResume fires if click_action: FLUTTER_NOTIFICATION_CLICK is set (see below).
https://pub.dev/packages/firebase_messaging#receiving-messages
So I need to add the data [click_action => FLUTTER_NOTIFICATION_CLICK] to all my notifications on my code, which is dirty, and it couple the code to flutter, which is dirtier.
But if I had an event I could add this data to all notification in only one place (a subscriber), and delete it if the mobile app comes to stop using flutter.
What do you think ?
composer require throws an error when running php 8.0.
php -v
): 8.0composer show | grep kreait
): (latest)Is PHP 8 already supported?
Trying to add and configure this bundle to a Symfony 3.4 project and getting this error on cache clear : There is no extension able to load the configuration for "kreait_firebase" (in "C:\laragon\www\DESiwid\app/config\config.yml"). Looked for namespace "kreait_firebase", found ""framework", "security", "twig", "monolog", "swiftmailer", "doctrine", "sensio_framework_extra", "des_iwid", "bazinga_js_translation", "cspoo_swiftmailer_mailgun", "exercise_html_purifier", "fm_elfinder", "fos_js_routing", "fos_user", "fresh_vich_uploader_serialization", "isometriks_spam", "ivory_ck_editor", "jms_aop", "jms_di_extra", "jms_i18n_routing", "jms_serializer", "jms_translation", "knp_menu", "knpu_oauth2_client", "lexik_jwt_authentication", "liip_imagine", "google_analytics_api", "nelmio_cors", "stof_doctrine_extensions", "assetic", "vich_uploader", "debug", "web_profiler", "sensio_distribution", "web_server"".
php -v
): PHP 7.2.16 (cli)composer show | grep kreait
):kreait/clock 1.0.1 A PHP 7.0 compatible clock abstraction
kreait/firebase-bundle 2.0.0 Symfony Bundle for the Firebase Admin SDK
kreait/firebase-php 5.2.0 Firebase Admin SDK
kreait/firebase-tokens 1.10.0 A library to work with Firebase tokens
Sending a single message works just fine. for example:
$title = 'My Notification Title';
$body = 'My Notification Body';
$notification = Notification::fromArray([
'title' => $title,
'body' => $body,
]);
$message = CloudMessage::withTarget('token', 'my-single-device-token')
->withNotification($notification)
->withData($data);
;
$messaging->send($message);
The above example is able to send a notification to my phone device, nice!
However, sending with sendMulticast
doesn't work. I've tried it like this:
$deviceTokens = ['my-single-device-token'];
$title = 'My Notification Title';
$body = 'My Notification Body';
$notification = Notification::fromArray([
'title' => $title,
'body' => $body,
]);
$message = CloudMessage::new();
$message->withNotification($notification);
$report = $messaging->sendMulticast($message, $deviceTokens);
The report yields:
Successful sends: 1
Failed sends: 0
The report says that the notification is sent, however nothing happens on my phone..
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=7.4",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"cocur/slugify": "^4.3",
"doctrine/annotations": "^1.14",
"doctrine/doctrine-bundle": "^2.10",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.15",
"friendsofphp/php-cs-fixer": "^3.13",
"gesdinet/jwt-refresh-token-bundle": "^1.1",
"knpuniversity/oauth2-client-bundle": "^2.15",
"kreait/firebase-bundle": "^4.1",
"league/fractal": "^0.20.1",
"league/oauth2-google": "^4.0",
"lexik/jwt-authentication-bundle": "^2.19",
"nelmio/api-doc-bundle": "^4.11",
"notfloran/mjml-bundle": "^3.7",
"patrickbussmann/oauth2-apple": "^0.2.10",
"predis/predis": "^2.1",
"ramsey/uuid-doctrine": "^2.0",
"sensio/framework-extra-bundle": "^6.2",
"sentry/sentry-symfony": "^4.7",
"symfony/asset": "5.4.*",
"symfony/console": "5.4.*",
"symfony/dotenv": "5.4.*",
"symfony/flex": "^1.17|^2",
"symfony/form": "5.4.*",
"symfony/framework-bundle": "5.4.*",
"symfony/mailer": "5.4.*",
"symfony/runtime": "5.4.*",
"symfony/security-bundle": "5.4.*",
"symfony/security-csrf": "5.4.*",
"symfony/twig-bundle": "5.4.*",
"symfony/uid": "5.4.*",
"symfony/validator": "5.4.*",
"symfony/yaml": "5.4.*",
"symfonycasts/reset-password-bundle": "^1.17",
"symfonycasts/verify-email-bundle": "^1.13"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-symfony": "^1.2",
"rector/rector": "^0.15.24",
"symfony/maker-bundle": "^1.43",
"symfony/stopwatch": "5.4.*",
"symfony/web-profiler-bundle": "5.4.*"
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true,
"symfony/runtime": true,
"phpstan/extension-installer": true,
"php-http/discovery": true
},
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd"
},
"cs": "php-cs-fixer fix --ansi -v",
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
],
"phpstan": [
"phpstan analyse src"
],
"rector": [
"vendor/bin/rector process src"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.4.*",
"docker": false
}
}
}
php 7.4.33 The PHP interpreter
$deviceTokens = ['my-single-device-token'];
$title = 'My Notification Title';
$body = 'My Notification Body';
$notification = Notification::fromArray([
'title' => $title,
'body' => $body,
]);
$message = CloudMessage::new();
$message->withNotification($notification);
$report = $messaging->sendMulticast($message, $deviceTokens);
-
No response
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.