kreait / firebase-bundle

A Symfony Bundle for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
135 stars 25 forks source link

Cannot autowire service "App\Service\PushService": argument "$messaging" of method "__construct()" references interface "Kreait\Firebase\Contract\Messaging" but no such service exists #46

Closed HackReb closed 1 year ago

HackReb commented 1 year ago

Describe the bug

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:

grafik

Installed packages

{
    "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.*"
        }
    }
}

PHP version and extensions

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

Steps to reproduce the issue.

# 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.

Error message/Stack trace

![grafik](https://user-images.githubusercontent.com/131554145/233843028-ca1b9f85-0d38-4544-b641-dad6e4bf4a83.png)

Additional information

No response

jeromegamez commented 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

HackReb commented 1 year ago

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?

jeromegamez commented 1 year ago

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.

jeromegamez commented 1 year ago

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.

HackReb commented 1 year ago

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.

jeromegamez commented 1 year ago

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 🤞🏻.

jeromegamez commented 1 year ago

I'll keep the issue open for the time being in case somebody else stumbled upon it and can provide additional insight.

HackReb commented 1 year ago

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)
jeromegamez commented 1 year ago

Of course! This is my output:

php bin/console debug:autowiring --all ``` ❯ php bin/console debug:autowiring --all Autowirable Types ================= The following classes & interfaces can be used as type-hints when autowiring: App\Controller\PushController App\Kernel (kernel) App\Service\PushService 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) 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) Pro-tip: use interfaces in your type-hints instead of classes to benefit from the dependency inversion principle. ```
composer.json contents ```json { "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 ``` ❯ composer show beste/clock 3.0.0 A collection of Clock implementations beste/json 1.2.1 A simple JSON helper to decode and encode JSON fig/http-message-util 1.1.5 Utility classes and constants for use with PSR-7 (psr/http-message) firebase/php-jwt v6.4.0 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec. google/auth v1.26.0 Google Auth Library for PHP google/cloud-core v1.50.0 Google Cloud PHP shared dependency, providing functionality useful to all components. google/cloud-storage v1.30.3 Cloud Storage Client for PHP google/crc32 v0.2.0 Various CRC32 implementations guzzlehttp/guzzle 7.5.1 Guzzle is a PHP HTTP client library guzzlehttp/promises 1.5.2 Guzzle promises library guzzlehttp/psr7 2.5.0 PSR-7 message implementation that also provides common utility methods kreait/firebase-bundle 5.0.0 Symfony Bundle for the Firebase Admin SDK kreait/firebase-php 7.2.1 Firebase Admin SDK kreait/firebase-tokens 4.2.0 A library to work with Firebase tokens lcobucci/clock 3.1.0 Yet another clock abstraction lcobucci/jwt 5.0.0 A simple library to work with JSON Web Token and JSON Web Signature monolog/monolog 3.3.1 Sends your logs to files, sockets, inboxes, databases and various web services mtdowling/jmespath.php 2.6.1 Declaratively specify how to extract elements from a JSON document psr/cache 3.0.0 Common interface for caching libraries psr/clock 1.0.0 Common interface for reading the clock. psr/container 2.0.2 Common Container Interface (PHP FIG PSR-11) psr/event-dispatcher 1.0.0 Standard interfaces for event handling. psr/http-client 1.0.2 Common interface for HTTP clients psr/http-factory 1.0.2 Common interfaces for PSR-7 HTTP message factories psr/http-message 1.1 Common interface for HTTP messages psr/log 3.0.0 Common interface for logging libraries psr/simple-cache 3.0.0 Common interfaces for simple caching ralouphie/getallheaders 3.0.3 A polyfill for getallheaders. riverline/multipart-parser 2.1.0 One class library to parse multipart content with encoding and charset support. rize/uri-template 0.3.5 PHP URI Template (RFC 6570) supports both expansion & extraction symfony/cache v6.2.8 Provides extended PSR-6, PSR-16 (and tags) implementations symfony/cache-contracts v3.2.1 Generic abstractions related to caching symfony/config v6.2.7 Helps you find, load, combine, autofill and validate configuration values of any kind symfony/console v6.2.8 Eases the creation of beautiful and testable command line interfaces symfony/dependency-injection v6.2.8 Allows you to standardize and centralize the way objects are constructed in your application symfony/deprecation-contracts v3.2.1 A generic function and convention to trigger deprecation notices symfony/dotenv v6.2.8 Registers environment variables from a .env file symfony/error-handler v6.2.9 Provides tools to manage errors and ease debugging PHP code symfony/event-dispatcher v6.2.8 Provides tools that allow your application components to communicate with each other by dispatching events and listening ... symfony/event-dispatcher-contracts v3.2.1 Generic abstractions related to dispatching event symfony/filesystem v6.2.7 Provides basic utilities for the filesystem symfony/finder v6.2.7 Finds files and directories via an intuitive fluent interface symfony/flex v2.2.5 Composer plugin for Symfony symfony/framework-bundle v6.2.9 Provides a tight integration between Symfony components and the Symfony full-stack framework symfony/http-foundation v6.2.8 Defines an object-oriented layer for the HTTP specification symfony/http-kernel v6.2.9 Provides a structured process for converting a Request into a Response symfony/polyfill-intl-grapheme v1.27.0 Symfony polyfill for intl's grapheme_* functions symfony/polyfill-intl-normalizer v1.27.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring v1.27.0 Symfony polyfill for the Mbstring extension symfony/routing v6.2.8 Maps an HTTP request to a set of configuration variables symfony/runtime v6.2.8 Enables decoupling PHP applications from global state symfony/service-contracts v3.2.1 Generic abstractions related to writing services symfony/string v6.2.8 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way symfony/var-dumper v6.2.8 Provides mechanisms for walking through any arbitrary PHP variable symfony/var-exporter v6.2.8 Allows exporting any serializable PHP data structure to plain PHP code symfony/yaml v6.2.7 Loads and dumps YAML files ```
HackReb commented 1 year ago

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...

jeromegamez commented 1 year ago

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!

itsamaik commented 3 weeks ago

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. 😅

jeromegamez commented 3 weeks ago

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... 🤔

itsamaik commented 3 weeks ago

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?

jeromegamez commented 2 weeks ago

I don't use Firebase or Symfony myself right now, so I can't say 🙈