Symfony 在FOSUserBundle事件中获取twilio实例
我正试图通过Twilio向在我的网站上注册的用户发送短信,我得到了vresh/Twilio捆绑包,效果很好。 我试图将twilio实例传递给该活动,但我认为我遗漏了一些东西,以下是我正在做的: 在config.yml中,我将服务设置为:Symfony 在FOSUserBundle事件中获取twilio实例,symfony,symfony-2.3,Symfony,Symfony 2.3,我正试图通过Twilio向在我的网站上注册的用户发送短信,我得到了vresh/Twilio捆绑包,效果很好。 我试图将twilio实例传递给该活动,但我认为我遗漏了一些东西,以下是我正在做的: 在config.yml中,我将服务设置为: services: registration.completed.listener: class: Jaguar\AloBundle\EventListener\RegistrationEventListener argu
services:
registration.completed.listener:
class: Jaguar\AloBundle\EventListener\RegistrationEventListener
arguments:
entityManager: ["@doctrine.orm.voipswitch_entity_manager", "vresh_twilio"]
tags:
- { name: kernel.event_subscriber, event: performOnRegistrationCompleted }
我已经声明了twilio配置:
vresh_twilio:
sid: 'xxx'
authToken: 'xxx'
version: '2010-04-01'
retryAttempts: 3
然后,在我的方法中,我尝试获取实例:
public function performOnRegistrationCompleted(UserEvent $event)
{
$twilio = $event->get('vresh_twilio');
}
但它失败了
请问有什么帮助吗
非常感谢 您的服务设置存在一些问题
@
符号@vresh_twilio
是一项服务,vresh_twilio
只是一个字符串entityManager
,以及一个值,该值也是一个数组,该数组的值为服务@doctor.orm.voipswitch\u entity\u manager
和字符串vresh\u twilio
services:
registration.completed.listener:
class: Jaguar\AloBundle\EventListener\RegistrationEventListener
arguments:
entityManager: "@doctrine.orm.voipswitch_entity_manager"
twilio: "@vresh_twilio"
// Or
// - @doctrine.orm.voipswitch_entity_manager
// - @vresh_twilio
// Or
// [@doctrine.orm.voipswitch_entity_manager, @vresh_twilio]
//
// As they all mean the same thing and the keys aren't
// used in your actual service __construct
tags:
- { name: kernel.event_subscriber, event: performOnRegistrationCompleted }
这意味着您的侦听器将有一个构造函数来接收这些服务,如
protected $entityManager;
protected $twilio;
public function __conctruct(ObjectManager $entityManager, TwilioWrapper $twilio)
{
$this->entityManager = $entityManager;
$this->twilio = $twilio;
}
这意味着您可以在类中使用$this->twilio
调用它
此外,从创建的角度来看,您希望注入的服务似乎是@twilio.api
,而不是@vresh_twilio
,因为它似乎不存在,但我可能错了(我自己没有使用捆绑包)