Closed HackReb closed 1 year ago
Unfortunately, I cannot reproduce the problem, here's what I did to try:
# Create a new Symfony project
composer create-project symfony/skeleton:"6.2.*" fb-46
cd fb-46
composer require kreait/firebase-bundle
# config/bundles.php
<?php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Kreait\Firebase\Symfony\Bundle\FirebaseBundle::class => ['all' => true],
];
# config/packages/firebase.yaml
kreait_firebase:
projects:
my_project:
credentials: '/path/to/my/firebase_credential.json'
# src/Service/PushService.php
<?php
declare(strict_types=1);
namespace App\Service;
use Kreait\Firebase\Contract\Messaging;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
final class PushService
{
private Messaging $messaging;
public function __construct(Messaging $messaging)
{
$this->messaging = $messaging;
}
public function sendy()
{
$deviceToken = '...';
$message = CloudMessage::withTarget('token', $deviceToken)
->withNotification(Notification::create('Testtitel', 'Inhalt'))
->withData(['key' => 'value']) // optional
;
$this->messaging->send($message);
}
}
# src/Controller/PushController.php
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Service\PushService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
final class PushController extends AbstractController
{
#[Route('/testing/sendPush', name: 'test_sendPush')]
public function sendPushTest(PushService $pushService)
{
$pushService->sendy();
return new Response("test");
}
}
Then, calling http://fb-46.test/testing/sendPush (I'm using Laravel Valet for local testing) works.
If you have multiple Firebase projects configured, you can add default: true
to one of them.
If you have multiple Firebase projects configured with none of them being the default, you can inject the component by naming the constructor parameter based on your configured projects.
For example, if you configured my_project
in the firebase.yaml
, you can also do
final class PushService
{
private Messaging $messaging;
public function __construct(Messaging $myProjectMessaging)
{
$this->messaging = $myProjectMessaging;
}
// ...
}
Let me know if it helps!
PS: There was an error in the README concerning the names of the named parameters, which I corrected in e513e3c893c47b2377c44dfecd2e1df2938c114c
Unfortunately i was not able to get this problem fixed. The problem occurs the moment i call the constructor with
private Messaging $messaging;
public function __construct(Messaging $messaging)
{
$this->messaging = $messaging;
}
and immediately it tells me:
Cannot resolve argument $pushService of "App\Controller\PushControllerNew::sendPushTest()": Cannot autowire service "App\Service\PushService": argument "$messaging" of method "__construct()" references interface "Kreait\Firebase\Contract\Messaging" but no such service exists. Did you create a class that implements this interface?
I have triple-checked if the bundle is enabled and sure it is. But somehow there seems to be a registration or something similar missing. I have removed every bit of code except for the controller that calls the url and the implementation of the service (with only the constructor). Problem still occurs... Cache cleared of course.
Should there be any entries for this plugin in the services.yaml?
Could you replicate my steps to confirm that they work (a completely fresh project, not removing elements from your current setup)?
I also just noticed that you also have kreait/laravel-firebase
- I don't think this should lead to conflicts, but I still recommend removing it, just to be sure.
If you want you can also push your current project (without the credentials file) to a public GitHub repo, I can then check it out and see if I can find something.
I have just created a completely blank skeleton project just like you did and i get the exact same error. So it has nothing to do with my configuration.
If you like i can send you login credentials to my testserver where i just setup the skeleton project.
Sorry, but logging into your server is more support than I can provide here.
Since I can't reproduce the problem, and due to the fact that the bundle is used in production, I currently have to assume it's not a problem in the bundle - I'd prefer to be wrong, though, because it would mean that I'd be able to fix it; for the moment I am at the end of my wits.
Should you ask on StackOverflow or another support forum about this, feel free to point them to this issue.
If you're planning to connect to FCM only, there might be other libraries out there that could work - I'm only aware of libraries that use the legacy FCM API, but as far as I know, the legacy API has been legacy for quite some time now and will probably work for the time being 🤞🏻.
I'll keep the issue open for the time being in case somebody else stumbled upon it and can provide additional insight.
Of course there is not need for individual support, there´s also other libraries using the legacy FCM API like you have mentioned.
I am just curious what is causing the problem since i really think that i am not the only one confronted with this issue since i have installed a completely skeleton installation of symfony (exactly like you did), and the problem still occurs.
Maybe you can post your php bin/console debug:autowiring --all and tell me if there is any other entry than in mine:
The following classes & interfaces can be used as type-hints when autowiring:
App\Controller\PushController
App\Kernel (kernel)
App\Service\PushService
Kreait\Firebase\Factory
Kreait\Firebase\Symfony\Bundle\DependencyInjection\Factory\ProjectFactory
CacheItemPoolInterface generates CacheItemInterface objects.
Psr\Cache\CacheItemPoolInterface (cache.app)
Psr\Container\ContainerInterface $parameterBag (parameter_bag)
Defines a dispatcher for events.
Psr\EventDispatcher\EventDispatcherInterface (event_dispatcher)
Describes a logger instance.
Psr\Log\LoggerInterface (logger)
SessionHandlerInterface (session.handler.native)
Redirects a request to another URL.
Symfony\Bundle\FrameworkBundle\Controller\RedirectController
TemplateController.
Symfony\Bundle\FrameworkBundle\Controller\TemplateController
ContainerBagInterface is the interface implemented by objects that manage service container parameters.
Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface (parameter_bag)
ParameterBagInterface is the interface implemented by objects that manage service container parameters.
Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface (parameter_bag)
Turns public and "container.reversible" services back to their ids.
Symfony\Component\DependencyInjection\ReverseContainer (reverse_container)
The EventDispatcherInterface is the central point of Symfony's event listener system. Listeners are registered on the manager and events are dispatched through the manager.
Symfony\Component\EventDispatcher\EventDispatcherInterface (event_dispatcher)
Provides basic utility to manipulate the file system.
Symfony\Component\Filesystem\Filesystem (filesystem)
Request stack that controls the lifecycle of requests.
Symfony\Component\HttpFoundation\RequestStack (request_stack)
A helper service for manipulating URLs within and outside the request scope.
Symfony\Component\HttpFoundation\UrlHelper (url_helper)
FileLocator uses the KernelInterface to locate resources in bundles.
Symfony\Component\HttpKernel\Config\FileLocator (file_locator)
Formats debug file links.
Symfony\Component\HttpKernel\Debug\FileLinkFormatter (debug.file_link_formatter)
Interface implemented by rendering strategies able to generate a URL for a fragment.
Symfony\Component\HttpKernel\Fragment\FragmentUriGeneratorInterface (fragment.uri_generator)
Interface implemented by HTTP cache stores.
Symfony\Component\HttpKernel\HttpCache\StoreInterface (http_cache.store)
HttpKernelInterface handles a Request to convert it to a Response.
Symfony\Component\HttpKernel\HttpKernelInterface (http_kernel)
The Kernel is the heart of the Symfony system.
Symfony\Component\HttpKernel\KernelInterface (kernel)
Signs URIs.
Symfony\Component\HttpKernel\UriSigner (uri_signer)
UrlGeneratorInterface is the interface that all URL generator classes must implement.
Symfony\Component\Routing\Generator\UrlGeneratorInterface (router.default)
UrlMatcherInterface is the interface that all URL matcher classes must implement.
Symfony\Component\Routing\Matcher\UrlMatcherInterface (router.default)
Holds information about the current request.
Symfony\Component\Routing\RequestContext (router.request_context)
Symfony\Component\Routing\RequestContextAwareInterface (router.default)
RouterInterface is the interface that all Router classes must implement.
Symfony\Component\Routing\RouterInterface (router.default)
Creates a URL-friendly slug from a given string.
Symfony\Component\String\Slugger\SluggerInterface (slugger)
Covers most simple to advanced caching needs.
Symfony\Contracts\Cache\CacheInterface (cache.app)
Allows invalidating cached items using tags.
Symfony\Contracts\Cache\TagAwareCacheInterface (cache.app.taggable)
Allows providing hooks on domain-specific lifecycles by dispatching events.
Symfony\Contracts\EventDispatcher\EventDispatcherInterface (event_dispatcher)
Of course! This is my output:
Alright, we got the problem. These services were not autowired in my configuraton:
Kreait\Firebase\Contract\Auth (kreait_firebase.my_project.auth)
Kreait\Firebase\Contract\Auth $myProjectAuth (kreait_firebase.my_project.auth)
The Firebase Realtime Database.
Kreait\Firebase\Contract\Database (kreait_firebase.my_project.database)
Kreait\Firebase\Contract\Database $myProjectDatabase (kreait_firebase.my_project.database)
Kreait\Firebase\Contract\DynamicLinks (kreait_firebase.my_project.dynamic_links)
Kreait\Firebase\Contract\DynamicLinks $myProjectDynamicLinks (kreait_firebase.my_project.dynamic_links)
Kreait\Firebase\Contract\Firestore (kreait_firebase.my_project.firestore)
Kreait\Firebase\Contract\Firestore $myProjectFirestore (kreait_firebase.my_project.firestore)
Kreait\Firebase\Contract\Messaging (kreait_firebase.my_project.messaging)
Kreait\Firebase\Contract\Messaging $myProjectMessaging (kreait_firebase.my_project.messaging)
The Firebase Remote Config.
Kreait\Firebase\Contract\RemoteConfig (kreait_firebase.my_project.remote_config)
Kreait\Firebase\Contract\RemoteConfig $myProjectRemoteConfig (kreait_firebase.my_project.remote_config)
Kreait\Firebase\Contract\Storage (kreait_firebase.my_project.storage)
Kreait\Firebase\Contract\Storage $myProjectStorage (kreait_firebase.my_project.storage)
I removed the library and reinstalled it and this time it autowired all of these services... why is that...
After testing more i found out that you have to create the firebase.yaml in the config/packages BEFORE you call "composer require kreait/firebase-bundle"
I don´t really understand why that is but it seems to be the solution. Crazy...
That's really weird, but I'm glad you were able to resolve the problem, and thanks for thinking of the autowiring debug, because I didn't! 🥳
I'll try reproducing the problem with the new input and if I can, try to find a solution or at least update the documentation.
Thanks again!
We are encountering the same issue at the moment. We were upgrading from Symfony 5.4 to 7.x and updated this package from 2.7.0 to 5.4.0. The package worked before, but now we are encountering the same issue as here.
Running php bin/console debug:autowiring --all | grep kreait
outputs
Kreait\Firebase\Factory
Kreait\Firebase\Symfony\Bundle\DependencyInjection\Factory\ProjectFactory
Reinstalling the library does not help. Still investigating further
Update 1
It looks like FirebaseExtension::load
is not getting any data in $configs
:
array(1) {
[0]=>
array(0) {
}
}
Update 2
Solved. Config file was named firebase.yml
instead of firebase.yaml
. After debugging Symfony itself, only to find out the config file was not being loaded, I realized this was the only file with another extension. I am surprised this is the cause, since I assumed that Symfony supported both? In my case, it is the solution though and easy to overlook. 😅
Wait what really?! Do you know if this is something I can handle in the bundle? I did use the correct file ending in the README, but I feel Symfony should be able to work with both file endings... 🤔
Wait what really?! Do you know if this is something I can handle in the bundle? I did use the correct file ending in the README, but I feel Symfony should be able to work with both file endings... 🤔
If I look at the output of php bin/console debug:config <BUNDLE>
for some other libraries, I get the same behavior when renaming from .yaml
to .yml
. It does explain why it broke after upgrading Symfony on our end. Does the same happen on your end?
I don't use Firebase or Symfony myself right now, so I can't say 🙈
Describe the bug
I am trying to do a simple push. The plugin is registred in the bundles.php
I have created a service file called "PushService.php" with a send function in it.
I am calling the function from my PushController.php
When i call the url /testing/sendPush i get the following error:
Installed packages
PHP version and extensions
Steps to reproduce the issue.
Error message/Stack trace
Additional information
No response