Use new extenders (#30)

This commit is contained in:
Sami Mazouz 2020-12-08 18:46:25 +01:00 committed by GitHub
parent 641688f280
commit 358a19f3c1
2 changed files with 8 additions and 44 deletions

View File

@ -7,7 +7,6 @@
* LICENSE file that was distributed with this source code.
*/
use Flarum\Api\Event\Serializing;
use Flarum\Extend;
use Flarum\Post\Event\Posted;
use Flarum\Pusher\Api\Controller\AuthController;
@ -15,7 +14,6 @@ use Flarum\Pusher\Listener;
use Flarum\Pusher\PusherNotificationDriver;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
return [
(new Extend\Frontend('forum'))
@ -33,7 +31,14 @@ return [
(new Extend\Notification())
->driver('pusher', PusherNotificationDriver::class),
function (Dispatcher $events, Container $container) {
(new Extend\Settings())
->serializeToForum('pusherKey', 'flarum-pusher.app_key')
->serializeToForum('pusherCluster', 'flarum-pusher.app_cluster'),
(new Extend\Event())
->listen(Posted::class, Listener\PushNewPost::class),
function (Container $container) {
$container->bind(Pusher::class, function ($app) {
$settings = $app->make(SettingsRepositoryInterface::class);
@ -50,8 +55,5 @@ return [
$options
);
});
$events->listen(Posted::class, Listener\PushNewPost::class);
$events->listen(Serializing::class, Listener\AddPusherApi::class);
},
];

View File

@ -1,38 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Pusher\Listener;
use Flarum\Api\Event\Serializing;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Settings\SettingsRepositoryInterface;
class AddPusherApi
{
/**
* @var SettingsRepositoryInterface
*/
protected $settings;
/**
* @param SettingsRepositoryInterface $settings
*/
public function __construct(SettingsRepositoryInterface $settings)
{
$this->settings = $settings;
}
public function handle(Serializing $event)
{
if ($event->isSerializer(ForumSerializer::class)) {
$event->attributes['pusherKey'] = $this->settings->get('flarum-pusher.app_key');
$event->attributes['pusherCluster'] = $this->settings->get('flarum-pusher.app_cluster');
}
}
}