mirror of
https://github.com/flarum/framework.git
synced 2024-11-26 02:10:09 +08:00
Get rid of event subscribers that resolve services too early, part 1
Refs flarum/core#1578.
This commit is contained in:
parent
bdf94f9218
commit
42b86cd3c1
|
@ -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);
|
||||
},
|
||||
];
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue
Block a user