Minishlink / web-push-bundle

Bundle around the WebPush library
MIT License
45 stars 10 forks source link

[Symfony 6] Problems with the "minishlink_web_push" service #25

Open vadegangas opened 1 year ago

vadegangas commented 1 year ago

Good morning

install the Minishlink/web-push-bundle v6.0.3 package on a symfony 6.

When trying to recover the service as the documentation says:

$webPush = $this->container->get('minishlink_web_push');

symfony complains that the indicated service is not found in the container.

So try dependency injection:

use Doctrine\Persistence\ManagerRegistry; use Minishlink\WebPush\WebPush;

class functionsNotifications { public function __construct(private WebPush $webPush, private ManagerRegistry $doctrine) {}

public function notify()
{
    dd($this->webPush);
}

}

but symfony throws the error

Cannot autowire service \"App\Utils\NotificationFunctions\": argument \"$webPush\" of method \"__construct()\" references class \"Minishlink\WebPush\WebPush\" but no such service exists. You should maybe alias this class to the existing \"minishlink_web_push\" service.

I would appreciate any help.

Minishlink commented 1 year ago

Hello, this bundle might not be compatible with the latest symfony versions, I haven't updated it in a while. There might have been a change in Symfony in how bundles are loaded, feel free to send a PR :) Otherwise you can use this other bundle that uses web-push, the same library that this bundle uses https://github.com/bpolaszek/webpush-bundle

vadegangas commented 1 year ago

Good again.

Thank you for your quick answer.

The bundle that you recommend requires pairing the endpoints with users and in my case that is not possible.

I'll look to see if I can find another.

It's a shame it doesn't last.

all the best.

franciscosantamaria commented 5 months ago

Hi @vadegangas , I know I'm late to this conversation, but you can still make this alias in your application and still using this bundle with Symfony 6:

Inside services.yaml:

services:

    //...

    Minishlink\WebPush\WebPush: '@minishlink_web_push'

Anyway, I can make a PR adding this alias in this bundle to avoid manually add it in every app that uses this bundle.

It's ok for you @Minishlink @stephanvierkant ?

Minishlink commented 2 months ago

Hello @franciscosantamaria, yes please if you can make it easer for others please do 🙏🏻