Get rid of event subscribers that resolve services too early, part 1

Refs flarum/core#1578.
This commit is contained in:
Franz Liedke 2018-12-15 17:26:25 +01:00
parent bdf94f9218
commit 42b86cd3c1
2 changed files with 3 additions and 14 deletions

View File

@ -9,6 +9,7 @@
* file that was distributed with this source code.
*/
use Flarum\Api\Event\Serializing;
use Flarum\Extend;
use Flarum\Pusher\Api\Controller\AuthController;
use Flarum\Pusher\Listener;
@ -26,7 +27,7 @@ return [
->post('/pusher/auth', 'pusher.auth', AuthController::class),
function (Dispatcher $events) {
$events->subscribe(Listener\AddPusherApi::class);
$events->listen(Serializing::class, Listener\AddPusherApi::class);
$events->subscribe(Listener\PushNewPosts::class);
},
];

View File

@ -14,7 +14,6 @@ namespace Flarum\Pusher\Listener;
use Flarum\Api\Event\Serializing;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Events\Dispatcher;
class AddPusherApi
{
@ -31,18 +30,7 @@ class AddPusherApi
$this->settings = $settings;
}
/**
* @param Dispatcher $events
*/
public function subscribe(Dispatcher $events)
{
$events->listen(Serializing::class, [$this, 'addAttributes']);
}
/**
* @param Serializing $event
*/
public function addAttributes(Serializing $event)
public function handle(Serializing $event)
{
if ($event->isSerializer(ForumSerializer::class)) {
$event->attributes['pusherKey'] = $this->settings->get('flarum-pusher.app_key');