wilpat / event-dispatcher-package

Simple package for dispatching events.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Event Dispather

A simple library for dispatching events in PHP

Installation

To install this package you can use composer

composer require  williamphp/event-dispatcher

Usage

 
// Create a new dispatcher

$dispather = new Dispatcher::make(
  listeners: [
    Path\To\Event::class => [
      Path\To\Listener::class,
    ]
  ]
)

$dispather = new Dispatcher(
  listeners: [],
  log: []
)

// Add event with listeners

$dispatcher->add(
  event: Path\To\Event::class,
  listeners: [
    Path\To\Listener::class,
  ]
)

// Append listeners to an event's Listener array

$dispatcher->add(
  event: Path\To\Event::class,
  listeners: [
    Path\To\Another\Listener::class,
  ]
)

// Dispatch
$dispatcher->dispatch(
  event: new Path\To\Event::class,
  debug: true,
)

// Get debug log items
$dispatcher->log(); // []

About

Simple package for dispatching events.


Languages

Language:PHP 100.0%