The purpose of this package isn't to be used within a project by the application as there is no point in creating another level of abstraction in that case BUT only to allow eonx-com packages to dispatch events without having to think about the event dispatcher used by each of our projects.

# Require package (Composer)

The recommended way to install this package is to use Composer (opens new window):

$ composer require eonx-com/easy-event-dispatcher

# Usage

This package will register the EonX\EasyEventDispatcher\Interfaces\EventDispatcherInterface within the DI container, allowing you to use dependency injection to dispatch your events.

// src/MyService.php

namespace App;

use App\MyEvent;
use EonX\EasyEventDispatcher\Interfaces\EventDispatcherInterface;

final class MyService
{
    /**
     * @var \EonX\EasyEventDispatcher\Interfaces\EventDispatcherInterface
     */
    private $eventDispatcher;

    public function __construct(EventDispatcherInterface $eventDispatcher)
    {
        $this->eventDispatcher = $eventDispatcher;
    }

    public function myMethod(string $myParam): void
    {
        $this->eventDispatcher->dispatch(new MyEvent($myParam));
    }
}