ssossossosso

Forums

Covering OroCRM topics, including community updates and company announcements.  Subscribe

This topic contains 2 replies, has 2 voices, and was last updated by golriz.nourani golriz.nourani 2 years, 8 months ago.

  • Creator
    Topic
  • #8892
    golriz.nourani
    golriz.nourani
    Participant

    Dear Sir
    I have jobs(which run by oro cron) inside of some of this jobs I want to dispatch an event so :

    ——————-

    namespace \Bundle\EventDispatcherBundle;

    final class SmsEvents
    {

    const SMS_RECEIVE = ‘sms.receive’;
    }

    —————–

    namespace \Bundle\EventDispatcherBundle\Event;

    use Symfony\Component\EventDispatcher\Event;
    use \Bundle\SmsBundle\Entity\Sms;
    use \Bundle\SmsBundle\Entity\SendSms;

    class SmsReceiveEvent extends Event
    {
    protected $sms;

    public function __construct(Sms $sms)
    {
    $this->sms = $sms;
    }

    public function getSms()
    {
    return $this->sms;
    }
    }

    ——————-
    namespace \Bundle\EventDispatcherBundle\EventListener;

    use \Bundle\EventDispatcherBundle\Event\SmsReceiveEvent;
    class SmsListener
    {
    public function onSmsReceivedAction(SmsReceiveEvent $event)
    {

    ************************************
    my code
    *********************************
    }
    }

    ————————–
    namespace \Bundle\SmsBundle\Command;

    use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
    use Symfony\Component\EventDispatcher\EventDispatcher;
    use \Bundle\EventDispatcherBundle\Event\SmsReceiveEvent;
    use \Bundle\EventDispatcherBundle\SmsEvents;
    use \Bundle\SmsBundle\Entity\Sms;

    class ProcessSMSCommand extends ContainerAwareCommand
    {
    protected function configure()
    {
    $this->setName(‘my:sms:process’);
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
    $dispatcher = $this->getContainer()->get(‘event_dispatcher’);
    $event = new SmsReceiveEvent($sms);
    $dispatcher->dispatch(SmsEvents::SMS_RECEIVE, $event);
    }
    }

    ————-
    service.yml of EventDispatcherBundle

    services:

    sms.listner:
    class: \Bundle\EventDispatcherBundle\EventListener\SmsListener
    tags:
    – { name: sms.event_listener, event: sms.receive, method: onSmsReceivedAction }

    ——————-
    my code have not any error but the code inside of listener was not run !!!
    please help me 🙁

    regards,
    Golriz

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #8958

    Alexandr Smaga
    Participant

    Hello!

    You use regular symfony event dispatcher, so your listener should be registered with tag name kernel.event_listener instead of sms.event_listener.

    #8988
    golriz.nourani
    golriz.nourani
    Participant

    Thanks a lot ,it works.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.