-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot autowire service "App\Service\PushService": argument "$messaging" of method "__construct()" references interface "Kreait\Firebase\Contract\Messaging" but no such service exists #46
Comments
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 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 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 e513e3c |
Unfortunately i was not able to get this problem fixed. The problem occurs the moment i call the constructor with
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 |
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:
|
Of course! This is my output: php bin/console debug:autowiring --all
composer.json contents{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"kreait/firebase-bundle": "^5.0",
"symfony/console": "6.2.*",
"symfony/dotenv": "6.2.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "6.2.*",
"symfony/runtime": "6.2.*",
"symfony/yaml": "6.2.*"
},
"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.*"
}
}
} Output of composer show
|
Alright, we got the problem. These services were not autowired in my configuraton:
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! |
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
![grafik](https://user-images.githubusercontent.com/131554145/233843028-ca1b9f85-0d38-4544-b641-dad6e4bf4a83.png)
Additional information
No response
The text was updated successfully, but these errors were encountered: