From 4227bd78d5ab2743e694bfd34784a5ccced20bef Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 21 Feb 2018 07:49:45 -0600 Subject: [PATCH] rename method --- .../Events/BroadcastNotificationCreated.php | 28 +++++++++---------- .../NotificationBroadcastChannelTest.php | 4 +-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php b/src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php index e5bf6b4ea871..d58ae7792a34 100644 --- a/src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php +++ b/src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php @@ -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(); } /** @@ -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() { - 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); } } diff --git a/tests/Notifications/NotificationBroadcastChannelTest.php b/tests/Notifications/NotificationBroadcastChannelTest.php index e360ab903be1..22ffc996d5ca 100644 --- a/tests/Notifications/NotificationBroadcastChannelTest.php +++ b/tests/Notifications/NotificationBroadcastChannelTest.php @@ -52,7 +52,7 @@ public function testNotificationIsBroadcastedWithCustomEventName() $notifiable, $notification, $notification->toArray($notifiable) ); - $eventName = $event->broadcastAs(); + $eventName = $event->broadcastType(); $this->assertSame('custom.type', $eventName); } @@ -115,7 +115,7 @@ public function toArray($notifiable) return ['invoice_id' => 1]; } - public function broadcastAs() + public function broadcastType() { return 'custom.type'; }