mirror of
https://github.com/flarum/core.git
synced 2025-10-19 02:36:08 +02:00
fixed the Bus command Handling forwarding the call to a matching Handler class
This commit is contained in:
28
src/Bus/BusServiceProvider.php
Normal file
28
src/Bus/BusServiceProvider.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Bus;
|
||||
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Illuminate\Contracts\Bus\Dispatcher as BusContract;
|
||||
use Illuminate\Contracts\Queue\Factory as QueueFactoryContract;
|
||||
|
||||
class BusServiceProvider extends AbstractServiceProvider
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
$this->app->bind(BusContract::class, function ($app) {
|
||||
return new Dispatcher($app, function ($connection = null) use ($app) {
|
||||
return $app[QueueFactoryContract::class]->connection($connection);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
19
src/Bus/Dispatcher.php
Normal file
19
src/Bus/Dispatcher.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Flarum\Bus;
|
||||
|
||||
use Illuminate\Bus\Dispatcher as BaseDispatcher;
|
||||
|
||||
class Dispatcher extends BaseDispatcher
|
||||
{
|
||||
public function getCommandHandler($command)
|
||||
{
|
||||
$handler = get_class($command) . 'Handler';
|
||||
|
||||
if (class_exists($handler)) {
|
||||
return $this->container->make($handler);
|
||||
}
|
||||
|
||||
return parent::getCommandHandler($command);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user