PHPackages                             myth/events - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. myth/events

AbandonedLibrary[Utility &amp; Helpers](/categories/utility)

myth/events
===========

A simple, fast, and flexible pub/sub events system for PHP with event prioritization.

091PHP

Since Jun 25Pushed 10y ago2 watchersCompare

[ Source](https://github.com/newmythmedia/events)[ Packagist](https://packagist.org/packages/myth/events)[ RSS](/packages/myth-events/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

myth:Events
===========

[](#mythevents)

[![Build Status](https://camo.githubusercontent.com/4c3d4c6684b5ebb39b6e8c164b1d77826986370b5ad90cfd3814d6f2be097dad/68747470733a2f2f7472617669732d63692e6f72672f6e65776d7974686d656469612f6576656e74732e737667)](https://travis-ci.org/newmythmedia/events)

This library provides a very simple, though quite powerful events system in PHP. It follows a publish/subscribe type of pattern, and uses a configuration file to store all of the event listeners in to reduce any potential coupling.

Setup
-----

[](#setup)

This library requires that a file exist someplace on the server that holds the configuration of the event listeners. The path to this file must be passed in as the only argument when instantiating the class. The definition of the event listeners is described below.

```
$events = new \Myth\Events\Events( 'path/to/config.php' );

```

This file will only be read in once during the lifetime of that instantiated class, and is not loaded until one of the classes methods are called.

Triggering Events
-----------------

[](#triggering-events)

You can trigger an event to happen by simply calling the `trigger()` method on the class. The first parameter is the name of the event to trigger. This name can be pretty much anything you desire. The only requirement is that the listeners listen for the same name.

```
$events->trigger('new_user');

```

If you want to pass data along to the listeners so they have something to work with, you can pass an array of data items as the second parameter.

```
$events->trigger('new_user', [$user, $role] );

```

### Canceling Listener Execution

[](#canceling-listener-execution)

Once the event is triggered, the listeners will be sorted by priority and ran one after another, the higher priority listener going first, naturally.

You can force the execution of the remaining listeners to stop by returning `false` from any listener.

Listening to Events
-------------------

[](#listening-to-events)

Listening to events simply means that you're telling the Events class that you want to be notified when that event is triggered, and that you want a chance to do something at that time. This is great for sending emails, checking authorization of the user, etc.

You define the listener inside of the config file using the `on()` method. The first parameter is the name of the event you want to run on. The second parameter is any callable function, but will often be closures.

```
$events->on('new_user', function ($user, $role) {
	Mail::queue('new_user_email', $user);
 });

```

You can define the order the events are executed by specifying the listener's priority in the third parameter. The priority is any whole number. The lower the number, the higher the priority.

```
$events->on('new_user', function ($user, $role) {
	Mail::queue('new_user_email', $user);
 }, 10);

```

There are three pre-defined values you can use if you don't need to specify any fine-grained orders:

```
EVENTS_PRIORITY_LOW = 200
EVENTS_PRIORITY_NORMAL = 100
EVENTS_PRIORITY_HIGH = 10

```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/65f693f45781e767ed8557b776fd775309e7a262629892b99cf38462931e9b26?d=identicon)[lonnieezell](/maintainers/lonnieezell)

---

Top Contributors

[![lonnieezell](https://avatars.githubusercontent.com/u/51931?v=4)](https://github.com/lonnieezell "lonnieezell (4 commits)")

### Embed Badge

![Health badge](/badges/myth-events/health.svg)

```
[![Health](https://phpackages.com/badges/myth-events/health.svg)](https://phpackages.com/packages/myth-events)
```

###  Alternatives

[thecodingmachine/class-explorer

Find the list of all your classes and more.

122.0M2](/packages/thecodingmachine-class-explorer)[glpi-project/tools

Various tools for GLPI and its plugins

12710.9k4](/packages/glpi-project-tools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
