Skip to content

Commit

Permalink
Improve the Notifications Service
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyCyborg committed Jul 25, 2019
1 parent 5037a38 commit 724fc92
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
8 changes: 5 additions & 3 deletions src/Notifications/ChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ class ChannelManager extends Manager implements DispatcherInterface
* Create a new manager instance.
*
* @param \Nova\Foundation\Application $app
* @param \Nova\Notifications\NotificationSender $sender
* @param \Nova\Events\Dispatcher $events
* @param \Nova\Bus\Dispatcher $bus
* @return void
*/
public function __construct(Application $app, NotificationSender $sender)
public function __construct(Application $app, EventDispatcher $events, BusDispatcher $bus)
{
$this->app = $app;

$this->sender = $sender;
//
$this->sender = new NotificationSender($this, $events, $bus);
}

/**
Expand Down
19 changes: 11 additions & 8 deletions src/Notifications/NotificationSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Nova\Notifications\Events\NotificationSending;
use Nova\Notifications\Events\NotificationSent;
use Nova\Notifications\ChannelManager;
use Nova\Notifications\SendQueuedNotifications;

use Ramsey\Uuid\Uuid;
Expand All @@ -27,18 +28,18 @@ class NotificationSender
protected $manager;

/**
* The command bus dispatcher instance.
* The events dispatcher instance.
*
* @var \Nova\Bus\Dispatcher
* @var \Nova\Events\Dispatcher
*/
protected $bus;
protected $events;

/**
* The events dispatcher instance.
* The command bus dispatcher instance.
*
* @var \Nova\Events\Dispatcher
* @var \Nova\Bus\Dispatcher
*/
protected $events;
protected $bus;


/**
Expand All @@ -48,8 +49,10 @@ class NotificationSender
* @param \Nova\Bus\Dispatcher $bus
* @return void
*/
public function __construct(EventDispatcher $events, BusDispatcher $bus)
public function __construct(ChannelManager $manager, EventDispatcher $events, BusDispatcher $bus)
{
$this->manager = $manager;

$this->events = $events;

$this->bus = $bus;
Expand Down Expand Up @@ -122,7 +125,7 @@ protected function sendToNotifiable($notifiable, $id, $notification, $channel)
}

if ($this->shouldSendNotification($notifiable, $notification, $channel)) {
$response = $this->driver($channel)->send($notifiable, $notification);
$response = $this->manager->channel($channel)->send($notifiable, $notification);

$this->events->dispatch(
new NotificationSent($notifiable, $notification, $channel, $response)
Expand Down
11 changes: 3 additions & 8 deletions src/Notifications/NotificationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@ class NotificationServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->singleton('notifications.sender', function ($app)
$this->app->singleton('notifications', function ($app)
{
$bus = $app->make(BusDispatcher::class);

return new NotificationSender($app['events'], $bus);
});

$this->app->singleton('notifications', function ($app)
{
return new ChannelManager($app, $app['notifications.sender']);
return new ChannelManager($app, $app['events'], $bus);
});
}

Expand All @@ -45,6 +40,6 @@ public function register()
*/
public function provides()
{
return array('notifications', 'notifications.sender');
return array('notifications');
}
}

0 comments on commit 724fc92

Please sign in to comment.