Skip to content
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

kreait_firebase.my_project.messaging #23

Closed
hsnbsst opened this issue Apr 3, 2020 · 8 comments
Closed

kreait_firebase.my_project.messaging #23

hsnbsst opened this issue Apr 3, 2020 · 8 comments

Comments

@hsnbsst
Copy link

hsnbsst commented Apr 3, 2020

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

@jeromegamez
Copy link
Member

jeromegamez commented Apr 3, 2020

It's written down in the README: https://github.com/kreait/firebase-bundle/blob/master/README.md#configuration - if something is unclear, please be more specific 🙏

@hsnbsst
Copy link
Author

hsnbsst commented Apr 3, 2020

okay i saw it but i can explain in more detail how to use the controller too,
$this->container->get("kreait_firebase.my_project.messaging"); I get an error when I use it this way

@jeromegamez
Copy link
Member

The services are private by default, if you want to get them as you described, in the configuration, set public: true for the projects you want to access this way.

@hsnbsst
Copy link
Author

hsnbsst commented Apr 3, 2020

Service "kreait_firebase.my_project.messaging" not found: even though it exists in the app's container, the container inside "App\Controller\AdminController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services. Try using dependency injection instead.

he did as you said but still gives an error like this

@jeromegamez
Copy link
Member

The error message is quite specific - the service is public and exists, but you can't access it in your application. In that case, I would do as the error message suggests: use Dependency Injection. You can do this in Symfony in your service definition files, something like:

// src/Controller/MyController.php

namespace App\Controller;

use Kreait\Firebase\Messaging;

class MyController
{
    /** @var Messaging */
    private $messaging;

    public function __construct(Messaging $messaging)
    {
        $this->messaging = $messaging;
    }
}
# config/services.yaml

services:
	App\Controller\MyController:
		arguments: ['@kreait_firebase.my_project.messaging']

@hsnbsst
Copy link
Author

hsnbsst commented Apr 3, 2020

I am designing a panel like this, for example, as a lot of applications and I will choose from these applications and notify the application I want from the same place, so if I do this way, how do I access the applications from the data in the database and how do I choose it? I hope I could tell I don't know English, I write with translation service, Thank you

@hsnbsst
Copy link
Author

hsnbsst commented Apr 3, 2020

namespace App\Service;
MyService

    public function sendMessage($pbaslik,$picerik,$pplayerid,$paketAdi,$image=null){



        $factori = new Factory();
        $mesaji = $factori->withServiceAccount($this->params->get('kernel.project_dir').'/config/firebase-hizmet-'.$paketAdi.'.json')->createMessaging();


        if ($pplayerid == "toplu") {
            $message = CloudMessage::withTarget('topic', "AllTopic")
                ->withNotification(Notification::create($pbaslik, $picerik,$image))
                ->withData(["click_action"=> "FLUTTER_NOTIFICATION_CLICK", "ekran"=> "bildirim"]);
        } else {
            $message = CloudMessage::withTarget('topic', $pplayerid)
                ->withNotification(Notification::create($pbaslik, $picerik,$image))
                ->withData(["click_action"=> "FLUTTER_NOTIFICATION_CLICK", "ekran"=> "bildirim"]);
        }

        try {
            $sonuc =   $mesaji->send($message);
        } catch (MessagingException $e) {
            $sonuc = $e->errors();
        } catch (FirebaseException $e) {
            $sonuc = $e->getMessage();
        }
        return $sonuc;

    }

I am trying this method for now

@jeromegamez
Copy link
Member

Your code has been translated as well 😅 (no problem, I understood what you meant).

I don't know what to tell you - if you use dependency injection as recommended by Symfony (or in general) and use the Symfony mechanics to inject the Firebase Services in your own services, you should be fine - but then, don't use the Factory directly. The purpose of the Bundle is to avoid this.

If you prefer to use the Factory directly, you can of course do so, but then I don't know what you need the bundle for 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants