Skip to content

Commit

Permalink
add guide how to use VoterLocator
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed Oct 3, 2016
1 parent 8b6bf9f commit 469d2b9
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,63 @@ foreach($events as $event) {
//$bus->pullAndPublish($purchase_order);
```

### If you want use VoterLocator, you must

Change configuration

```yml
domain_event:
locator: 'voter'
```

Implement `VoterListenerInterface` in your event listener

```php
use GpsLab\Domain\Event\EventInterface;
use GpsLab\Domain\Event\Listener\ListenerInterface;

class SendEmailOnPurchaseOrderCreated implements VoterListenerInterface
{
private $mailer;

public function __construct(\Swift_Mailer $mailer)
{
$this->mailer = $mailer;
}

public function isSupportedEvent(EventInterface $event);
{
// you can add more conditions
return $event instanceof PurchaseOrderCreatedEvent;
}

public function handle(EventInterface $event)
{
$message = $this->mailer
->createMessage()
->setTo('recipient@example.com')
->setBody(sprintf(
'Purchase order created at %s for customer #%s',
$event->getCreateAt()->format('Y-m-d'),
$event->getCustomer()->getId()
));

$this->mailer->send($message);
}
}
```

Register event listener

```yml
services:
domain_event.listener.purchase_order.send_email_on_created:
class: SendEmailOnPurchaseOrderCreated
arguments: [ '@mailer' ]
tags:
- { name: domain_event.voter_listener }
```

## License

This bundle is under the [MIT license](http://opensource.org/licenses/MIT). See the complete license in the file: LICENSE

0 comments on commit 469d2b9

Please sign in to comment.