Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Latest
## Fixes
* [#192](https://github.com/cleverage/process-bundle/issues/192) Fix CommandRunnerTask: only pass the `options` option to `Process::setOptions()`, support string `commandline` through `Process::fromShellCommandline()`, validate option types. Update documentation, add tests.
* [#194](https://github.com/cleverage/process-bundle/issues/194) Fix ProcessLauncherTask: the `process_options` normalizer returned an array despite its scalar return type, so the task always failed with a `TypeError`. Update documentation, add tests.
* [#189](https://github.com/cleverage/process-bundle/issues/189) Fix EventDispatcherTask: dispatch the event under the `event_name` option (regression since v4.0). `event_name` is now optional: when `null` (default), the event is dispatched under its class name. Update documentation.

v5.0
-----
Expand Down
26 changes: 19 additions & 7 deletions docs/reference/tasks/event_dispatcher_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Possible outputs
Options
-------

| Code | Type | Required | Default | Description |
|--------------|----------|:--------:|---------|---------------------------------------------------------------|
| `event_name` | `string` | **X** | | Name of the event (see Notes: currently not used to dispatch) |
| `passive` | `bool` | | `true` | If `true`, the input is passed to the output before dispatch |
| Code | Type | Required | Default | Description |
|--------------|----------------|:--------:|---------|----------------------------------------------------------------------------|
| `event_name` | `string\|null` | | `null` | Name of the dispatched event, `null` to use the event class name (see Notes) |
| `passive` | `bool` | | `true` | If `true`, the input is passed to the output before dispatch |

Examples
--------
Expand All @@ -50,6 +50,18 @@ push_data_event:
Notes
-----

The event is dispatched without an explicit name (`$eventDispatcher->dispatch($event)`), so its name is the event
class name. Listeners must therefore subscribe to `CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent`; the
`event_name` option is required and validated but not used for dispatching.
The event is dispatched with `$eventDispatcher->dispatch($event, $eventName)`:

* when `event_name` is set, listeners must subscribe to that name:

```php
#[AsEventListener(event: 'myapp.data_queue')]
public function onDataQueue(EventDispatcherTaskEvent $event): void
{
$input = $event->getState()->getInput();
}
```

* when `event_name` is `null`, the event name is the event class name, so listeners must subscribe to
`CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent`. Every `EventDispatcherTask` without `event_name` then
triggers the same listeners.
6 changes: 3 additions & 3 deletions src/Task/Event/EventDispatcherTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public function execute(ProcessState $state): void

$event = new EventDispatcherTaskEvent($state);

$this->eventDispatcher->dispatch($event);
$this->eventDispatcher->dispatch($event, $options['event_name']);
}

protected function configureOptions(OptionsResolver $resolver): void
{
$resolver->setRequired(['event_name']);
$resolver->setDefault('event_name', null);
$resolver->setDefault('passive', true);
$resolver->setAllowedTypes('event_name', ['string']);
$resolver->setAllowedTypes('event_name', ['null', 'string']);
$resolver->setAllowedTypes('passive', ['boolean']);
}
}
Loading