PHPackages                             laxity7/yii2-event-service - 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. laxity7/yii2-event-service

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

laxity7/yii2-event-service
==========================

Yii2 events provide a simple observer pattern implementation, allowing you to subscribe and listen for various events that occur within your application.

1.0.1(10mo ago)08MITPHPPHP &gt;=7.4|&gt;=8.0

Since Sep 18Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/laxity7/yii2-event-service)[ Packagist](https://packagist.org/packages/laxity7/yii2-event-service)[ Docs](https://github.com/laxity7/yii2-event-service)[ RSS](/packages/laxity7-yii2-event-service/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (3)Used By (0)

Event service for Yii2
======================

[](#event-service-for-yii2)

[![License](https://camo.githubusercontent.com/973c77853c7237bca5a19bd390b6a4d1206b71247240312ea292f6a3462cdc5b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c6178697479372f796969322d6576656e742d736572766963652e737667)](https://github.com/laxity7/yii2-event-service/blob/master/LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/20d9fafb94c956b80f50a78f9fd947f66566779a683129c52135978d5e8467ca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6178697479372f796969322d6576656e742d736572766963652e737667)](https://packagist.org/packages/laxity7/yii2-event-service)[![Total Downloads](https://camo.githubusercontent.com/589b8d3152e4955bfc415d85bc7d60f6840e78022b463a32f0a7350cdf8e7486/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6178697479372f796969322d6576656e742d736572766963652e737667)](https://packagist.org/packages/laxity7/yii2-event-service)

Yii2 events provide a simple observer pattern implementation, allowing you to subscribe and listen for various events that occur within your application.

Install
-------

[](#install)

Install via composer

```
composer require laxity7/yii2-event-service
```

How to use
----------

[](#how-to-use)

### 1. Create an event class

[](#1-create-an-event-class)

It will be an any class that contains event data. You can also use the default Yii2 event class `yii\base\Event`.

For example:

```
namespace App\Events;

use yii\base\Event;

final readonly class PaymentEvent
{
    public function __construct(
        public float $amount,
        public string $currency,
        public string $description,
    ) {
    }
}
```

### 2. Create a listener class

[](#2-create-a-listener-class)

It will be a class that contains a method `handle` or `__invoke` that will be called when the event is dispatched. The method must accept an event object as an argument.

For example:

```
namespace App\Events\listeners;

use App\Events\PaymentEvent;

final class PaymentListener
{
    //public function __invoke(PaymentEvent $event): void
    public function handle(PaymentEvent $event): void
    {
        Yii::info('Event: ' . get_class($event) . ' Trigger: ' . __METHOD__, __METHOD__);
    }
}
```

> Note: You can also use a closure as a listener. The closure must accept an event object as an argument.

### 3. Subscribe to the event

[](#3-subscribe-to-the-event)

Add the following code to your configuration file:

```
'components' => [
    'eventDispatcher' => [
         'class' => \Laxity7\Yii2\Components\EventServiceProvider::class,
         'listen' => [
             \App\Events\PaymentEvent::class => [
                 \App\Events\listeners\PaymentListener::class, // listener class
                 function (\App\Events\PaymentEvent $event) { // closure
                    Yii::info('Event: ' . get_class($event) . ' Trigger: ' . __METHOD__, __METHOD__);
                 },
             ],
         ],
    ],
],
```

### 4. Dispatch the event

[](#4-dispatch-the-event)

```
use App\Events\PaymentEvent;
use Laxity7\Yii2\Components\Event;

$event = new PaymentEvent(100, 'USD', 'Payment for goods');
\Yii::$app->eventDispatcher->dispatch($event);
// or use the helper
Event::dispatch($event);
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance53

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

Total

2

Last Release

324d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

eventsyii2yii2-event-service

### Embed Badge

![Health badge](/badges/laxity7-yii2-event-service/health.svg)

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

###  Alternatives

[brussens/yii2-maintenance-mode

Maintenance mode component for Yii framework 2.x.x version.

78263.0k5](/packages/brussens-yii2-maintenance-mode)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1359.3k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

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