PHPackages                             yarcode/simple-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. yarcode/simple-events

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

yarcode/simple-events
=====================

Simple event dispatching library for PHP

1.1(7y ago)21.7k11MITPHPPHP ^7

Since Oct 7Pushed 7y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (1)Versions (4)Used By (1)

Simple Events
=============

[](#simple-events)

Simple event dispatching library for PHP

[![SensioLabsInsight](https://camo.githubusercontent.com/c61fa347976c27cf7215ff81b4ae4d95084a5e7351e8a3800424a540904593ad/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f36373339323635312d373065312d343363372d623831352d3663646564306439386533322f6269672e706e67)](https://insight.sensiolabs.com/projects/67392651-70e1-43c7-b815-6cded0d98e32)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6557173fb1bd63a9bccd8a7f24947862b38dedbc829ccb945435e1f98354a7cb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f796172636f64652f73696d706c652d6576656e74732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yarcode/simple-events/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/d53b8e819927804f534df84f61ef05e2c779025bd0fcb4e804f307c6237dc516/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f796172636f64652f73696d706c652d6576656e74732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yarcode/simple-events/?branch=master)[![Build Status](https://camo.githubusercontent.com/24365d087fb815193d823bf233fbc28c7a8324d5c6420ebe1303dde03616eb18/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f796172636f64652f73696d706c652d6576656e74732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yarcode/simple-events/build-status/master)[![GitHub license](https://camo.githubusercontent.com/30ce0c324d6429faf3fb1a7b39b9ad2eef053cd0e273aca378bf8f3dbc24fefc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f796172636f64652f73696d706c652d6576656e74732e737667)](https://github.com/yarcode/simple-events/blob/master/LICENSE)

Installation
------------

[](#installation)

### Composer

[](#composer)

The preferred way to install this extension is through [Composer](http://getcomposer.org/).

Either run

```
composer require yarcode/simple-events

```

or add

```
"yarcode/simple-events": "*"

```

to the require section of your `composer.json`

Usage
-----

[](#usage)

### Via EventEmitterTrait

[](#via-eventemittertrait)

Attach `\YarCode\Events\EventEmitterTrait` to your class to make it `EventEmitter`

```
class MyClass {
    use \YarCode\Events\EventEmitterTrait;
    ...
}
$emitter = new MyClass();
```

### Standalone EventEmitter

[](#standalone-eventemitter)

Or create an instance of `\YarCode\Events\EventEmitter`.

```
$emitter = new \YarCode\Events\EventEmitter();
```

### Adding listeners

[](#adding-listeners)

You can add `callable` listener for any string event name.

```
$emitter->addListener('TestEvent', function (\YarCode\Events\Event $event) {
    echo "{$event->name} was emitted";
});
$emitter->addListener('TestEvent', function (\YarCode\Events\Event $event) {
    echo "{$event->name} was emitted one more time";
});

```

### Emitting events

[](#emitting-events)

You can emit named event with default event object.

```
$emitter->emit('TestEvent');
// TestEvent was emitted
// TestEvent was emitted one more time
```

Or you can pass `\YarCode\Events\Event` object to the listeners.

```
$event = new \YarCode\Events\Event();
$event->payload['key'] = 'value';
$emitter->emit('TestEvent', $event);
// TestEvent was emitted
// TestEvent was emitted one more time
```

You could pass any data as event payload. It would be passed as a first parameter to a listener callable.

```
$data = ['foo', 'bar'];
$emitter->emit('MixedDataEvent', $data);
```

### Removing listeners

[](#removing-listeners)

You can remove one concrete listener.

```
$callback = function (\YarCode\Events\Event $event) {
    echo "{$event->name} was emitted third time";
});
$emitter->addListener('TestEvent', $callback);
$emitter->removeListener('TestEvent', $callback);

```

Or remove all the listeners for the event.

```
$emitter->removeAllListeners('TestEvent');
```

Or remove all the listeners for all events.

```
$emitter->removeAllListeners();
```

### Breaking the execution

[](#breaking-the-execution)

Set the `$event->handled` property to `true` to stop the further listeners execution.

```
$emitter->addListener('TestEvent', function (\YarCode\Events\Event $event) {
    $event->handled = true;
});
$emitter->addListener('TestEvent', function (\YarCode\Events\Event $event) {
    echo "This callback for {$event->name} would never run";
});
$emitter->emit('TestEvent');
```

### Accessing the emitter from the listener

[](#accessing-the-emitter-from-the-listener)

Emitter object is being passed as a second parameter to a listener.

```
$emitter->addListener('TestEmitterAccessEvent', function ($data, $emitter) {
    echo "Hello";
    $emitter->emit('TestEmitterAccessEvent2', $data);
});
$emitter->addListener('TestEmitterAccessEvent2', function ($data) {
    echo " World";
});
$emitter->emit('TestEmitterAccessEvent');
// Hello World
```

License
-------

[](#license)

MIT

Links
-----

[](#links)

- [GitHub repository](https://github.com/yarcode/simple-events)
- [Composer package](https://packagist.org/packages/yarcode/simple-events)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~369 days

Total

3

Last Release

2767d ago

Major Versions

0.1 → 1.02017-08-14

PHP version history (2 changes)0.1PHP &gt;=5.4

1.0PHP ^7

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1297270?v=4)[Vahid G](/maintainers/lagman)[@lagman](https://github.com/lagman)

---

Top Contributors

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

---

Tags

eventeventemitterphp7traiteventevent dispatcheremitterevent-emitterbusdispatcherevent bus

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[doctrine/event-manager

The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.

6.1k501.1M115](/packages/doctrine-event-manager)[league/event

Event package

1.6k141.6M184](/packages/league-event)[evenement/evenement

Événement is a very simple event dispatching library for PHP

1.3k147.0M319](/packages/evenement-evenement)[contributte/event-dispatcher

Best event dispatcher / event manager / event emitter for Nette Framework

292.4M19](/packages/contributte-event-dispatcher)[dazzle-php/event

Dazzle Events &amp; Dispatchers.

161.7k6](/packages/dazzle-php-event)

PHPackages © 2026

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