solilokiam/async-event-dispatcher

An asynchronous event dispatcher for symfony

dev-master 2014-11-16 17:58 UTC

This package is not auto-updated.

Last update: 2024-04-23 00:58:29 UTC


README

Build Status SensioLabsInsight Dependency Status Scrutinizer Code Quality

This component is an async event dispatcher based on the Symfony's event dispatcher component but in a fire and forget way. Right now it needs Redis to work but if you use another queue system it's really easy to extend and use.

Warning

This code is not ready for production. This is still a Work in progress, things may change a lot over time.

Installation

Using composer

Add following lines to your composer.json file:

"require": {
      ...
      "solilokiam/async-event-dispatcher": "dev-master"
    },

How do you dispatch events?

If you've already used symfony event dispatcher it's really simple to use. First you need to create your own event. This event must extend AsyncEvent . Once you've got your event created you need to dispatch it using the AsyncEventDispatcher. You need to inject an object that implements EventDriverInterface when you instantiate the AsyncEventDispatcher class. This component provides you with a RabbitMq implementation of the interface. Feel free to create your own if you need it.

In the following example you can see how to do it:

namespace Foo\Events;

use Solilokiam\AsyncEventDispatcher\AsyncEvent;

class FooAsyncEvent extends AsyncEvent
{
    protected $foo;

    public function setFoo($value)
    {
        $this->foo = $value;

        return $this;
    }

    public function getFoo()
    {
        return $this->foo;
    }
}
$redirEventDriver = new RedisDriver($redisConfig);

$asyncEventDispatcher = new AsyncEventDispatcher($redisEventDriver);

$fooEvent = new FooAsyncEvent();
$fooEvent->setFoo('whatever');

$dispatcher->dispatch('foo.event', $fooEvent);

How do you define event listeners?

TODO

How do you consume dispatcher events?

TODO

License

AsyncEventDispatcher is licensed under the MIT License. See the LICENSE file for full details.