solilokiam / async-event-dispatcher
An asynchronous event dispatcher for symfony
Requires
- predis/predis: 1.0.*
- symfony/serializer: 2.5.6
- videlalvaro/php-amqplib: 2.2.*
Requires (Dev)
- fabpot/php-cs-fixer: @stable
- mockery/mockery: dev-master
- phpmd/phpmd: dev-master
- phpunit/phpunit: 4.2.*
- squizlabs/php_codesniffer: dev-master
This package is not auto-updated.
Last update: 2024-11-19 04:05:37 UTC
README
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.