Bus Dispatcher is not a singleton, preventing any extensibility
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Bug Report
**Current Behavior**
The reason to use the bus dispatcher is to make commands extensible. However it's currently not possible to extend them in any way.
Related flarum/issue-archive#345
**Steps to Reproduce**
1. Register a bus pipe from an extension:
```php
return [
function (\Illuminate\Contracts\Bus\Dispatcher $bus) {
$bus->pipeThrough([
function($command, $next)
{
die('command stopped by pipe');
},
]);
},
];
```
2. Try creating a discussion or replying
3. No error happens, even though the pipe should stop any command from executing
**Expected Behavior**
It should be possible to register pipes and custom mappings on the bus dispatcher.
**Environment**
- Flarum version: beta 13, beta 14
**Possible Solution**
This can be fixed by using a `singleton` in the `BusServiceProvider`
https://github.com/flarum/core/blob/967cd0e3ca793be8d83f8ba569fb0beb85452e85/src/Bus/BusServiceProvider.php#L22
That's what Laravel is using in its bundled `BusServiceProvider`
**Additional Context**
Looking at the code it must be broken since at least beta 8.
Evidence from that 2016 post suggests it was working at one point in the past https://discuss.flarum.org/d/3384-hooking-into-bus-dispatch-commands/2
Contributor guide
Research direction
Start with src/Bus/BusServiceProvider.php at the linked registration and compare it with Laravel's bundled BusServiceProvider. Reproduce the extension pipe example, then verify that creating a discussion or replying is intercepted by the registered pipe and that custom mappings can be registered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100