Вход Регистрация
Файл: vendor/laravel/framework/src/Illuminate/Notifications/Channels/BroadcastChannel.php
Строк: 117
<?php

namespace IlluminateNotificationsChannels;

use 
IlluminateContractsEventsDispatcher;
use 
IlluminateNotificationsEventsBroadcastNotificationCreated;
use 
IlluminateNotificationsMessagesBroadcastMessage;
use 
IlluminateNotificationsNotification;
use 
RuntimeException;

class 
BroadcastChannel
{
    
/**
     * The event dispatcher.
     *
     * @var IlluminateContractsEventsDispatcher
     */
    
protected $events;

    
/**
     * Create a new broadcast channel.
     *
     * @param  IlluminateContractsEventsDispatcher  $events
     * @return void
     */
    
public function __construct(Dispatcher $events)
    {
        
$this->events $events;
    }

    
/**
     * Send the given notification.
     *
     * @param  mixed  $notifiable
     * @param  IlluminateNotificationsNotification  $notification
     * @return array|null
     */
    
public function send($notifiableNotification $notification)
    {
        
$message $this->getData($notifiable$notification);

        
$event = new BroadcastNotificationCreated(
            
$notifiable$notificationis_array($message) ? $message $message->data
        
);

        if (
$message instanceof BroadcastMessage) {
            
$event->onConnection($message->connection)
                  ->
onQueue($message->queue);
        }

        return 
$this->events->dispatch($event);
    }

    
/**
     * Get the data for the notification.
     *
     * @param  mixed  $notifiable
     * @param  IlluminateNotificationsNotification  $notification
     * @return mixed
     *
     * @throws RuntimeException
     */
    
protected function getData($notifiableNotification $notification)
    {
        if (
method_exists($notification'toBroadcast')) {
            return 
$notification->toBroadcast($notifiable);
        }

        if (
method_exists($notification'toArray')) {
            return 
$notification->toArray($notifiable);
        }

        throw new 
RuntimeException('Notification is missing toArray method.');
    }
}
Онлайн: 0
Реклама