PHPackages                             derywat/php-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. derywat/php-events

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

derywat/php-events
==================

PHP library for sending and receiving events.

0.1.1(2mo ago)0241MITPHP

Since Dec 11Pushed 2mo agoCompare

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

READMEChangelogDependenciesVersions (3)Used By (1)

PHP library for sending and receiving events.
=============================================

[](#php-library-for-sending-and-receiving-events)

Library allows to send events from class to all registered receivers.

Sending event from class
------------------------

[](#sending-event-from-class)

### Define custom event class

[](#define-custom-event-class)

Example class implements sending string message.

```
use derywat\events\EventInterface;

class MyCustomEventClass implements EventInterface {

	protected $message;

	public function __construct(string $message){
		$this->message = $message;
	}

	public function __tostring(): string {
		return "{$this->message}";
	}

}
```

### Send event

[](#send-event)

Use custom event class to report event to all receivers.

```
use derywat\events\EventsProducerInterface;
use derywat\events\EventsProducerTrait;

class MyClass implements EventsProducerInterface {
	use EventsProducerTrait;

	protected function myMethodWithEvent(){
		//report event
		$this->reportEvent(new MyCustomEventClass("message to send in event"));
	}
}
```

Receiving events
----------------

[](#receiving-events)

### Receiving events in class

[](#receiving-events-in-class)

Events may be received in any class by implementing EventsReceiverInterface.

```
use derywat\events\EventsReceiverInterface;

class MyEventReceivingClass implements EventsReceiverInterface {

	public function eventHandler(EventInterface $event):void {
		$class = get_class($event);
		switch($class) {
			case MyCustomEventClass::class:
				//handle events of MyCustomEventClass here
				break;
		}
	}

}
```

Multiple objects of classes implementing EventsReceiverInterface may be added using registerEventReceiver method.

```
$receiverInstance = new MyEventReceivingClass();
$producerInstance = new MyClass();
//register receiver in producer
$producerInstance->registerEventReceiver($receiverInstance);
```

### Receiving events in closures defined outside of class instance

[](#receiving-events-in-closures-defined-outside-of-class-instance)

Adding EventReceiverTrait implements EventsReceiverInterface in any class.

```
use derywat\events\EventsReceiverInterface;
use derywat\events\EventReceiverTrait;

class MyEventReceivingClass implements EventsReceiverInterface {
	use EventReceiverTrait;
}
```

Trait implements event handler using event handling closures. Event handlers are external to class and class instance object.

```
use derywat\events\EventsReceiver;

$receiverInstance = new MyEventReceivingClass();
$receiverInstance->addEventHandlerClosure(
	function(EventInterface $event):void {
		$class = get_class($event);
		switch($class) {
			case MyCustomEventClass::class:
				//handle events of MyCustomEventClass here
				break;
		}
	}
);

$producerInstance = new MyClass();
$producerInstance->registerEventReceiver($receiverInstance);
```

### Using EventsReceiver with EventsReceiver object

[](#using-eventsreceiver-with-eventsreceiver-object)

Event handling can be implemented with instance of predefined EventsReceiver class.

```
use derywat\events\EventsReceiver;

$producerInstance = new MyClass();

$producerInstance->registerEventReceiver(
	//create instance of EventsReceiver
	(new EventsReceiver())->addEventHandlerClosure(
		function(EventInterface $event):void {
			$class = get_class($event);
			switch($class) {
    			case MyCustomEventClass::class:
			        //handle events of MyCustomEventClass here
			        break;
			}
		}
	)
);
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance82

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 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 ~69 days

Total

2

Last Release

89d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fc9a4843bfd807b6a86c2518447cfceb6d3d883dd68424cc66aec8552d4a52fa?d=identicon)[derywat](/maintainers/derywat)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[kartik-v/bootstrap-star-rating

A simple yet powerful JQuery star rating plugin for Bootstrap.

1.1k4.5M5](/packages/kartik-v-bootstrap-star-rating)[elegantly/laravel-seo

An Elegant &amp; flexible SEO tag builder for Laravel

122.9k](/packages/elegantly-laravel-seo)

PHPackages © 2026

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