PHPackages                             wyrihaximus/broadcast - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. wyrihaximus/broadcast

ActiveComposer-plugin[Queues &amp; Workers](/categories/queues)

wyrihaximus/broadcast
=====================

✨ Statically on composer install/update compiled (async) event dispatcher

2.6.1(3mo ago)989.4k↑1100%[1 PRs](https://github.com/WyriHaximus/php-broadcast/pulls)1MITMakefilePHP ^8.4CI passing

Since Dec 17Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/WyriHaximus/php-broadcast)[ Packagist](https://packagist.org/packages/wyrihaximus/broadcast)[ GitHub Sponsors](https://github.com/WyriHaximus)[ RSS](/packages/wyrihaximus-broadcast/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (18)Used By (1)

Broadcast
=========

[](#broadcast)

✨ Statically on composer install/update compiled event dispatcher

[![Continuous Integration](https://github.com/wyrihaximus/php-broadcast/workflows/Continuous%20Integration/badge.svg)](https://github.com/wyrihaximus/php-broadcast/workflows/Continuous%20Integration/badge.svg)[![Latest Stable Version](https://camo.githubusercontent.com/3f05720a34393fb6b7f8eb99767e07f10a6dfd74a9e3e74c625fbbd632fccfce/68747470733a2f2f706f7365722e707567782e6f72672f77797269686178696d75732f62726f6164636173742f762f737461626c65)](https://packagist.org/packages/wyrihaximus/broadcast)[![Total Downloads](https://camo.githubusercontent.com/0b24a4f5737b80cd6dca3e2965ca76691b810c9c16dc98fd444d518d354a6a04/68747470733a2f2f706f7365722e707567782e6f72672f77797269686178696d75732f62726f6164636173742f646f776e6c6f616473)](https://packagist.org/packages/wyrihaximus/broadcast/stats)[![Type Coverage](https://camo.githubusercontent.com/d97360d2eaeb5e3d816a433070a98df4918b23b2dfa8756c00ee1542183a8641/68747470733a2f2f73686570686572642e6465762f6769746875622f57797269486178696d75732f7068702d62726f6164636173742f636f7665726167652e737667)](https://shepherd.dev/github/WyriHaximus/php-broadcast)[![License](https://camo.githubusercontent.com/67cd4ea405f1ecb09e15cc9feaa58881d68857007bfcefb7dd7465f9dee7761e/68747470733a2f2f706f7365722e707567782e6f72672f77797269686178696d75732f62726f6164636173742f6c6963656e7365)](https://packagist.org/packages/wyrihaximus/broadcast)

Installation
============

[](#installation)

To install via [Composer](http://getcomposer.org/), use the command below, it will automatically detect the latest version and bind it with `^`.

```
composer require wyrihaximus/broadcast

```

Usage
=====

[](#usage)

Any package setting the following in their `composer.json` will have its autoloading directories and files scanned for any classes that implements `WyriHaximus\Broadcast\Contracts\Listener`. Each public method with a concrete object type hint on classes implementing `WyriHaximus\Broadcast\Contracts\Listener` will be registered as an event listener for that object in the type hint.

```
{
  "extra": {
    "wyrihaximus": {
      "broadcast": {
        "has-listeners": true
      }
    }
  }
}
```

To use those automatically picked up event listeners, use the `WyriHaximus\Broadcast\ContainerListenerProvider`, which needs a `PSR-11` container to work.

The following example uses the dummy event and listener coming with this package:

```
use WyriHaximus\Broadcast\ContainerListenerProvider;
use WyriHaximus\Broadcast\Dispatcher;
use WyriHaximus\Broadcast\Dummy\Event;

$event = new Event();

(new Dispatcher(new ContainerListenerProvider($container), $logger))->dispatch($event)
```

Listener
--------

[](#listener)

The following listener is from one of my apps and listeners both on initialize and shutdown events. The logic has been taken out, but logging is left intact to demonstrate a simple listener example.

```
