Skip to content

Commit

Permalink
rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 21, 2018
1 parent 6626512 commit 4227bd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,19 @@ public function broadcastOn()
}

/**
* Get the type of the broadcasted event.
* Get the broadcast channel name for the event.
*
* @return string
*/
public function broadcastAs()
protected function channelName()
{
if (method_exists($this->notification, 'broadcastAs')) {
return $this->notification->broadcastAs();
if (method_exists($this->notifiable, 'receivesBroadcastNotificationsOn')) {
return $this->notifiable->receivesBroadcastNotificationsOn($this->notification);
}

return get_class($this->notification);
$class = str_replace('\\', '.', get_class($this->notifiable));

return $class.'.'.$this->notifiable->getKey();
}

/**
Expand All @@ -86,23 +88,19 @@ public function broadcastWith()
{
return array_merge($this->data, [
'id' => $this->notification->id,
'type' => $this->broadcastAs(),
'type' => $this->broadcastType(),
]);
}

/**
* Get the broadcast channel name for the event.
* Get the type of the notification being broadcast.
*
* @return string
*/
protected function channelName()
public function broadcastType()

This comment has been minimized.

Copy link
@antonkomarev

antonkomarev Feb 21, 2018

Contributor

@taylorotwell maybe it's better to name optional Notification method as notificationType() or eventType() and then we will be able to use it for DatabaseChannel() as well? Because now if we will use broadcastType() it wouldn't be clear why broadcast type used in database.

This comment has been minimized.

Copy link
@antonkomarev

antonkomarev Feb 21, 2018

Contributor

Or even getType().

{
if (method_exists($this->notifiable, 'receivesBroadcastNotificationsOn')) {
return $this->notifiable->receivesBroadcastNotificationsOn($this->notification);
}

$class = str_replace('\\', '.', get_class($this->notifiable));

return $class.'.'.$this->notifiable->getKey();
return method_exists($this->notification, 'broadcastType')
? $this->notification->broadcastType()
: get_class($this->notification);
}
}
4 changes: 2 additions & 2 deletions tests/Notifications/NotificationBroadcastChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testNotificationIsBroadcastedWithCustomEventName()
$notifiable, $notification, $notification->toArray($notifiable)
);

$eventName = $event->broadcastAs();
$eventName = $event->broadcastType();

$this->assertSame('custom.type', $eventName);
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public function toArray($notifiable)
return ['invoice_id' => 1];
}

public function broadcastAs()
public function broadcastType()
{
return 'custom.type';
}
Expand Down

0 comments on commit 4227bd7

Please sign in to comment.