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

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

guanguans/yii-event
===================

Elegant usage events in Yii. - 在 Yii 中优雅的使用事件。

v1.0.6(4y ago)145232MITPHP

Since Dec 5Pushed 4y ago1 watchersCompare

[ Source](https://github.com/guanguans/yii-event)[ Packagist](https://packagist.org/packages/guanguans/yii-event)[ Docs](https://github.com/guanguans/yii-event)[ Fund](https://www.guanguans.cn/images/wechat.jpeg)[ RSS](/packages/guanguans-yii-event/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (6)Versions (8)Used By (0)

yii-event
=========

[](#yii-event)

> Elegant usage events in Yii. - 在 Yii 中优雅的使用事件。

[![](./docs/usage.png)](./docs/usage.png)

[![Tests](https://github.com/guanguans/yii-event/workflows/Tests/badge.svg)](https://github.com/guanguans/yii-event/actions)[![Check & fix styling](https://github.com/guanguans/yii-event/workflows/Check%20&%20fix%20styling/badge.svg)](https://github.com/guanguans/yii-event/actions)[![codecov](https://camo.githubusercontent.com/c85d512747ffa79ca9316e338dfc8258014fb74f9988206d9647d11785539925/68747470733a2f2f636f6465636f762e696f2f67682f6775616e6775616e732f7969692d6576656e742f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d55524746415753365334)](https://codecov.io/gh/guanguans/yii-event)[![Latest Stable Version](https://camo.githubusercontent.com/0d4ab8f52e1430bf9d28d5614724ee3797fccd4302381de6ea40a77fa672cf57/68747470733a2f2f706f7365722e707567782e6f72672f6775616e6775616e732f7969692d6576656e742f76)](//packagist.org/packages/guanguans/yii-event)[![Total Downloads](https://camo.githubusercontent.com/67e89c2ecb9410597d6cfd04e76c5cd68fe8eda9b01ffff9c4b6e316683d107e/68747470733a2f2f706f7365722e707567782e6f72672f6775616e6775616e732f7969692d6576656e742f646f776e6c6f616473)](//packagist.org/packages/guanguans/yii-event)[![License](https://camo.githubusercontent.com/ad962a7c7a1a8ceed6601115e412cd30812034ad8003f9a0acc28eac854abd45/68747470733a2f2f706f7365722e707567782e6f72672f6775616e6775616e732f7969692d6576656e742f6c6963656e7365)](//packagist.org/packages/guanguans/yii-event)

Requirement
-----------

[](#requirement)

- Yii &gt; 2.0

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

[](#installation)

```
$ composer require guanguans/yii-event --prefer-dist -vvv
```

Configuration
-------------

[](#configuration)

```
...
'components' => [
    ...
    'event' => [
        'class' => \Guanguans\YiiEvent\Event::class,
        'listen' => [
            \app\events\ExampleEvent::class => [
                \app\listeners\ExampleListener::class,
            ],
        ],
    ],
    ...
],
...
```

Usage
-----

[](#usage)

### Create `app\events\ExampleEvent.php`

[](#create-appeventsexampleeventphp)

```
namespace app\events;

use yii\base\Event;

class ExampleEvent extends Event
{
    public $name = 'example';
}
```

### Create `app\listeners\ExampleListener.php`

[](#create-applistenersexamplelistenerphp)

```
namespace app\listeners;

use Guanguans\YiiEvent\ListenerInterface;
use yii\base\Event;

class ExampleListener implements ListenerInterface
{
    public function handle(Event $event)
    {
        // to do something.
        var_export($event->name);
        // var_export($event->data);
    }
}
```

### Dispatch event

[](#dispatch-event)

```
Yii::$app->event->dispatch(new ExampleEvent());
// Yii::$app->event->dispatch(new ExampleEvent(), $data);
// or
event(new ExampleEvent());
// event(new ExampleEvent(), $data);
```

### Output result

[](#output-result)

```
'example'
```

Testing
-------

[](#testing)

```
$ composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [guanguans](https://github.com/guanguans)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.9% 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 ~89 days

Recently: every ~133 days

Total

7

Last Release

1500d ago

### Community

Maintainers

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

---

Top Contributors

[![guanguans](https://avatars.githubusercontent.com/u/22309277?v=4)](https://github.com/guanguans "guanguans (37 commits)")[![forecho](https://avatars.githubusercontent.com/u/1725326?v=4)](https://github.com/forecho "forecho (1 commits)")[![ImgBotApp](https://avatars.githubusercontent.com/u/31427850?v=4)](https://github.com/ImgBotApp "ImgBotApp (1 commits)")

---

Tags

eventeventsyii2yii2-extensioneventyii2yiiyii-event

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[brussens/yii2-maintenance-mode

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

78263.0k5](/packages/brussens-yii2-maintenance-mode)

PHPackages © 2026

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