knplabs / rad-domain-event
Provide RAD Domain Event component
Installs: 47 451
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 28
Forks: 3
Open Issues: 3
Requires
- php: ~7.0
- doctrine/orm: ^2.5
- symfony/config: ^2.6 || ~3.0 || ~4.0
- symfony/dependency-injection: ^2.6 || ~3.0 || ~4.0
- symfony/http-kernel: ^2.6 || ~3.0 || ~4.0
Requires (Dev)
- phpspec/phpspec: ^2.4
This package is auto-updated.
Last update: 2022-09-23 13:37:14 UTC
README
Unfortunately we decided to not maintain this project anymore (see why). If you want to mark another package as a replacement for this one please send an email to hello@knplabs.com.
Knp Rad Domain Event
A lightweight domain event pattern implementation for Doctrine2.
Official maintainers:
Installation
With composer :
$ composer require knplabs/rad-domain-event
If you are using Symfony you can update your app/AppKernel.php
file:
public function registerBundles() { $bundles = array( // bundles here ... new Knp\Rad\DomainEvent\Bundle\DomainEventBundle(); ); }
Usage
Setup your entity
First, make sure your entity implements the Provider interface and uses the ProviderTrait.
use Knp\Rad\DomainEvent; class MyEntity implements DomainEvent\Provider { use DomainEvent\ProviderTrait; }
Raise event
Trigger any event from your entity, through the raise
method.
It will be turned into a Knp\Rad\DomainEvent\Event object and dispatched once your entity has been flushed.
use Knp\Rad\DomainEvent; class MyEntity implements DomainEvent\Provider { // ... public function myFunction($arg) { // your function behavior $this->raise('myEventName', ['anyKey' => $anyValue]); } }
Listen to this event
use Knp\Rad\DomainEvent\Event; class MyListener { public function onMyEventName(Event $event) { // your function behavior } }
Then, of course, register your listener.
app.event_listener.my_event_listener: class: App\EventListener\MyEventListener tags: - { name: kernel.event_listener, event: myEventName, method: 'onMyEventName' }