OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

Forums Forums OroCRM OroCRM – Programming Questions Eventdispatcher

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

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #25012

    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
  • #25013

    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.

    #25014

    golriz.nourani
    Participant

    Thanks a lot ,it works.

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

The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.

Back to top