命令内部的getContainer()-> get('A service')

时间:2019-06-19 10:18:14

标签: symfony

在我的config.yml中,我已经定义了它以便处理通知

rms_push_notifications:
    android:
        timeout: 5 # Seconds to wait for connection timeout, default is 5
        fcm:
            api_key: "key"
            use_multi_curl: false
    ios:
        timeout: 60 # Seconds to wait for connection timeout, default is 60
        sandbox: true
        pem: '%kernel.project_dir%/pushcert.pem'
        passphrase: *****

我已经定义了一个命令来测试通知发送

services.yml

app.command.app_sendNotif:
    class: AppRefactoredBundle\Command\SendNotif
    public: true
    arguments: ['@service_container']
    tags:
        - { name: console.command }

命令

class SendNotif extends ContainerAwareCommand
{

    private $container;

    public function __construct(Container $containers)
    {
        parent::__construct();
        $this->container = $containers;
    }

    protected function configure()
    {
        // On set le nom de la commande
        $this->setName('app:sendNotif');

        // On set la description
        $this->setDescription("Permet de controler le timeout des offres et demandes");

        // On set l'aide
        $this->setHelp("Cette commande ne prend pas d'argument et travailler sur toutes les offres et demandes");
    }

    public function execute(InputInterface $input, OutputInterface $output){

        // --------------------- TEST ENVOIE NOTIF ANDROID ET IOS -------------------------------------------//


        $output->writeln("Send IOS");
        $message = new iOSMessage();
        $message->setMessage('Oh my! A push notification IOS !');
        $message->setDeviceIdentifier('d03b98b9f5260e2523b03a614d4d2a01278524aaccff8c8b8ea0617e6471c992');
        var_dump($this->container->get('rms_push_notifications'));

        $output->writeln("Send Done");

    }
}

问题是我可以得到我的容器...但是我无法获得在config.yml中定义的rms_push_notifications

我收到此错误

在AbstractClient.php第33行中:

类型错误:函数Buzz \ Client \ AbstractClient :: __ construct()的参数太少,/ var / www / project / api / vendor / richsage / rms-push-notifications-bundle / RMS / PushNotificationsBundle / Service / OS / AndroidGCMNotification.php在第81行及至少
  预期1个

1 个答案:

答案 0 :(得分:0)

好的,所以实际上问题与使用Buzz的RMS有关。 这意味着我们必须将Buzz依赖项添加到我们的composer.json中(官方文档中未指出)。然后可以了