1
0
mirror of https://github.com/flarum/core.git synced 2025-08-10 10:24:46 +02:00

Get rid of event subscribers that resolve services too early

Refs flarum/core#1578.
This commit is contained in:
Franz Liedke
2018-12-18 00:18:48 +01:00
parent 42b86cd3c1
commit 97d118939b
4 changed files with 103 additions and 96 deletions

View File

@@ -11,8 +11,12 @@
use Flarum\Api\Event\Serializing;
use Flarum\Extend;
use Flarum\Notification\Event\Sending;
use Flarum\Post\Event\Posted;
use Flarum\Pusher\Api\Controller\AuthController;
use Flarum\Pusher\Listener;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
return [
@@ -26,8 +30,26 @@ return [
(new Extend\Routes('api'))
->post('/pusher/auth', 'pusher.auth', AuthController::class),
function (Dispatcher $events) {
function (Dispatcher $events, Container $container) {
$container->bind(Pusher::class, function ($app) {
$settings = $app->make(SettingsRepositoryInterface::class);
$options = [];
if ($cluster = $settings->get('flarum-pusher.app_cluster')) {
$options['cluster'] = $cluster;
}
return new Pusher(
$settings->get('flarum-pusher.app_key'),
$settings->get('flarum-pusher.app_secret'),
$settings->get('flarum-pusher.app_id'),
$options
);
});
$events->listen(Posted::class, Listener\PushNewPost::class);
$events->listen(Sending::class, Listener\PushNotification::class);
$events->listen(Serializing::class, Listener\AddPusherApi::class);
$events->subscribe(Listener\PushNewPosts::class);
},
];