PHPackages                             phpgears/event - 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. phpgears/event

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

phpgears/event
==============

Event handling

0.3.4(6y ago)06654MITPHPPHP ^7.1CI failing

Since Nov 21Pushed 5y ago1 watchersCompare

[ Source](https://github.com/phpgears/event)[ Packagist](https://packagist.org/packages/phpgears/event)[ Docs](https://github.com/phpgears/event)[ RSS](/packages/phpgears-event/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (17)Versions (13)Used By (4)

[![PHP version](https://camo.githubusercontent.com/d0b5687c6812c5d52d86a548e09db527eeb7860f82adbb677de00a36ddbed1b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344372e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](http://php.net)[![Latest Version](https://camo.githubusercontent.com/423a87389d6084b1add439b30751223895d157c062921f363da6296be2dec7be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70687067656172732f6576656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpgears/event)[![License](https://camo.githubusercontent.com/e76a0eedb278a91fd4179a6419cf01c1725f0ca985608615f0a649c7221d1c21/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70687067656172732f6576656e742e7376673f7374796c653d666c61742d737175617265)](https://github.com/phpgears/event/blob/master/LICENSE)

[![Build Status](https://camo.githubusercontent.com/572a080e5b6c2e276a1bdcccd083f86e69ffc97df8aef82675ca19f5f4ec9c62/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f70687067656172732f6576656e742e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/github/phpgears/event)[![Style Check](https://camo.githubusercontent.com/faf17a62d3837178f5a1b6a6e107340074d59b3a7c911b429030f05370b540b3/68747470733a2f2f7374796c6563692e696f2f7265706f732f3134393033373438362f736869656c64)](https://styleci.io/repos/149037486)[![Code Quality](https://camo.githubusercontent.com/d538e552e7dca4d9b24272588c719d06aa0133489bb53602cb2d1ed818fcee4a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f70687067656172732f6576656e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/phpgears/event)[![Code Coverage](https://camo.githubusercontent.com/befd4af09a25ad40c7b22d9a8ca1b7ab56a16a6adad2a11ea5cdd6c21e7fe102/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f70687067656172732f6576656e742e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/phpgears/event)

[![Total Downloads](https://camo.githubusercontent.com/cb92eb80a60318e812173d8d5b737055d3c358461ce4ff320be0b7b6aa73a236/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70687067656172732f6576656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpgears/event/stats)[![Monthly Downloads](https://camo.githubusercontent.com/701f52eb397684fcbca131befad2561755d2028eee7a1efb00e7ce23dc1096ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f70687067656172732f6576656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpgears/event/stats)

Event
=====

[](#event)

Event base classes and handling interfaces

This package only provides the building blocks to events

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

[](#installation)

### Composer

[](#composer)

```
composer require phpgears/event

```

Usage
-----

[](#usage)

Require composer autoload file

```
require './vendor/autoload.php';
```

### Events

[](#events)

Events are DTOs that carry all the information of an already happened situation

You can create your own by implementing `Gears\Event\Event` or extending from `Gears\Event\AbstractEvent` which ensures event immutability and payload and metadata is composed only of **scalar values** which is a very interesting capability. AbstractEvent has a private constructor forcing you to create events using *occurred* static method on your named constructors

```
use Gears\Event\AbstractEvent;

class CreateUserEvent extends AbstractEvent
{
    public static function fromPersonalData(
        string $name,
        string lastname,
        \DateTimeImmutable $birthDate
    ): self {
        return static::occurred([
            'name' => $name,
            'lastname' => $lastname,
            'birthDate' => $birthDate->format('U'),
        ]);
    }
}
```

In case of a event without any payload you could extend `Gears\Event\AbstractEmptyEvent`

```
use Gears\Event\AbstractEvent;

class CreateUserEvent extends AbstractEmptyEvent
{
    public static function instance(): self {
        return self::occurred();
    }
}
```

### Collection

[](#collection)

Events can be grouped into iterables implementing `Gears\Event\EventCollection` objects, `Gears\Event\EventArrayCollection` and `Gears\Event\EventIteratorCollection` are provided accepting only instances of `Gears\Event\Event`

#### Async events

[](#async-events)

Having event assuring all of its payload is composed only of scalar values proves handy when you want to delegate event handling to a message queue system such as RabbitMQ, Gearman or Apache Kafka, serializing/deserializing scalar values is trivial in any format and language

Asynchronous behaviour must be implemented at EventBus level, event bus must be able to identify async events (a map of events, implementing an interface, by a payload parameter, ...) and enqueue them

If you want to have asynchronous behaviour on your EventBus have a look [phpgears/event-async](https://github.com/phpgears/event-async), there you'll find all the necessary pieces to start your async event bus

### Handlers

[](#handlers)

Events are handed over to implementations of `Gears\Event\EventHandler`, available in this package is `AbstractEventHandler` which verifies the type of the event so you can focus only on implementing the handling logic

```
class CreateUserEventHandler extends AbstractEventHandler
{
    protected function getSupportedEventType(): string
    {
        return CreateUserEvent::class;
    }

    protected function handleEvent(Event $event): void
    {
        /* @var CreateUserEvent $event */

        $user = new User(
            $event->getName(),
            $event->getLastname(),
            $event->getBirthDate()
        );

        [...]
    }
}
```

Have a look at [phpgears/dto](https://github.com/phpgears/dto) fo a better understanding of how events are built out of DTOs and how they hold their payload

### Event Bus

[](#event-bus)

Only `Gears\Event\EventBus` interface is provided, you can easily use any of the good bus libraries available out there by simply adding an adapter layer

#### Implementations

[](#implementations)

Event bus implementations currently available

- [phpgears/event-symfony-messenger](https://github.com/phpgears/event-symfony-messenger) uses Symfony's Messenger
- [phpgears/event-symfony-event-dispatcher](https://github.com/phpgears/event-symfony-event-dispatcher) uses Symfony's Event Dispatcher

Contributing
------------

[](#contributing)

Found a bug or have a feature request? [Please open a new issue](https://github.com/phpgears/event/issues). Have a look at existing issues before.

See file [CONTRIBUTING.md](https://github.com/phpgears/event/blob/master/CONTRIBUTING.md)

License
-------

[](#license)

See file [LICENSE](https://github.com/phpgears/event/blob/master/LICENSE) included with the source code for a copy of the license terms.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

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.

###  Release Activity

Cadence

Every ~51 days

Total

11

Last Release

2263d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c50421f1ab4148354dc2dd5dcaba168656b17ea913b310d112deb39a6f73ca1?d=identicon)[juliangut](/maintainers/juliangut)

---

Top Contributors

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

---

Tags

eventimmutable

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpgears-event/health.svg)

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

###  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.0k517.6M149](/packages/doctrine-event-manager)[league/event

Event package

1.6k149.1M200](/packages/league-event)[laminas/laminas-eventmanager

Trigger and listen to events within a PHP application

1.0k71.7M251](/packages/laminas-laminas-eventmanager)[winzou/state-machine

A very lightweight yet powerful PHP state machine

52413.9M18](/packages/winzou-state-machine)[spatie/laravel-event-sourcing

The easiest way to get started with event sourcing in Laravel

9094.1M28](/packages/spatie-laravel-event-sourcing)[spatie/laravel-google-calendar

Manage events on a Google Calendar

1.4k1.7M21](/packages/spatie-laravel-google-calendar)

PHPackages © 2026

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