Skip to content

Commit

Permalink
Fix bugs with PopulateDebugCommandPass. Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Nov 26, 2017
1 parent 4e70ad6 commit cdd43be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ Install via composer
composer require bornfreee/tactician-domain-events-bundle
```

Add bundle to `AppKernel.php`:

```php
$bundles = [
// ...
new \BornFree\TacticianDomainEventBundle\TacticianDomainEventBundle(),
];
```

Configuration
-----

Expand All @@ -31,7 +40,7 @@ tactician_domain_event:
Usage
-----
This bundle allows you to automatically have Domain Events dispatched by `EventDispatcher`. It also allows to register event listeners as the Symfony Services.
This bundle allows you to automatically have Domain Events dispatched by `EventDispatcher`. It also allows to register event listeners and subscribers as the Symfony Services.
You can register as many listeners as you want for each Domain Event.

First, we need to install the Tactician official Bundle to integrate the command bus library:
Expand Down Expand Up @@ -69,6 +78,15 @@ app.listener.send_email:
Notice the tag `tactician.event_listener`. The bundle automatically finds all services tagged with this tag and adds the listener to `EventDispatcher`.

By default, event listener shold have public `__invoke` function. If you want to have regular method name, it's possible to it to the service configuration:

```yaml
app.listener.send_email:
class: AppBundle\EventListener\SendEmailAfterUserIsCreatedListener
tags:
- { name: tactician.event_listener, event: App\Domain\Events\UserWasCreated, method: send }
```

This is all configuration you need to start using the Tactician command bus with Domain Events.

Let's have an example where we create a new user and a `UserWasCreated` domain event is dispatched:
Expand Down
6 changes: 4 additions & 2 deletions src/DependencyInjection/Compiler/PopulateDebugCommandPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public function process(ContainerBuilder $container)
foreach ($listeners as $serviceId => $tags) {
foreach ($tags as $tag) {
$listener = $container->getDefinition($serviceId);
$events[$tag['event']][] = $listener->getClass().'::'.$tag['method'];
$method = array_key_exists('method', $tag) ? $tag['method'] : '__invoke';

$events[$tag['event']][] = $listener->getClass() . '::' . $method;
}
}

Expand All @@ -35,7 +37,7 @@ public function process(ContainerBuilder $container)
}

foreach ($subscriber->getSubscribedEvents() as $event => $method) {
$events[$event][] = get_class($subscriber).'::'.$method;
$events[$event][] = get_class($subscriber) . '::' . $method[1];
}
}

Expand Down

0 comments on commit cdd43be

Please sign in to comment.