musonza/chat

View on GitHub
src/Eventing/EventDispatcher.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Musonza\Chat\Eventing;

use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Musonza\Chat\Chat;

class EventDispatcher
{
    protected $event;

    public function __construct(DispatcherContract $event)
    {
        $this->event = $event;
    }

    public function dispatch(array $events)
    {
        if (Chat::broadcasts()) {
            foreach ($events as $event) {
                $eventName = $this->getEventName($event);
                $this->event->dispatch($eventName, $event);
            }
        }
    }

    public function getEventName($event)
    {
        return str_replace('\\', '.', get_class($event));
    }
}