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

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

phoole/event
============

Slim, powerful and full compatible PSR-14 event manager library for PHP

1.1.0(6y ago)932.5k↓46.1%21Apache-2.0PHPPHP &gt;=7.2.0

Since Oct 17Pushed 6y ago1 watchersCompare

[ Source](https://github.com/phoole/event)[ Packagist](https://packagist.org/packages/phoole/event)[ RSS](/packages/phoole-event/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (1)

event
=====

[](#event)

[![Build Status](https://camo.githubusercontent.com/050f487e1636995e41fd6dea2a1f01f348a87814a519a7a2788436f3b3173259/68747470733a2f2f7472617669732d63692e636f6d2f70686f6f6c652f6576656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/phoole/event)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/72be7632a5a5783fe94cad7579712adecec542f5e4861b69c8579aa9cc1c4fc2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70686f6f6c652f6576656e742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phoole/event/?branch=master)[![Code Climate](https://camo.githubusercontent.com/18b1019a20317108e6de81e32c5eb3d49de669ffd3c9e0e34fcc6d5a281a8acf/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f70686f6f6c652f6576656e742f6261646765732f6770612e737667)](https://codeclimate.com/github/phoole/event)[![PHP 7](https://camo.githubusercontent.com/45115fc8245ad8f51fc2133b1fd3d9014c370ce17ec3377117d5eedc1e80f170/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f70686f6f6c652f6576656e74)](https://packagist.org/packages/phoole/event)[![Latest Stable Version](https://camo.githubusercontent.com/fb50cc615bb26ca85e8cf5acc809efef0ff520d89592d0553080526c085424cf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f70686f6f6c652f6576656e74)](https://packagist.org/packages/phoole/event)![License](https://camo.githubusercontent.com/462a82afaf505c0599ef4cfc14fcfa6b545c0d134503d5f4265daf6626d73588/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686f6f6c652f6576656e74)

Slim, powerful and full compatible PSR-14 event manager library for PHP.

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

[](#installation)

Install via the `composer` utility.

```
composer require "phoole/event"

```

or add the following lines to your `composer.json`

```
{
    "require": {
       "phoole/event": "1.*"
    }
}
```

Features
--------

[](#features)

- Full PSR-14 support
- Support for classes want event-triggering capability with `EventCapableTrait`
- Support for classes want event-listening capability with `ListenerCapableTrait`

Usage
-----

[](#usage)

- Quick start

    ```
    use Phoole\Event\Provider;
    use Phoole\Event\Dispatcher;
    use Phoole\Event\Events\StoppableEvent;

    // create your own event class
    class MyEvent extends StoppableEvent {
    }

    // an invokable class for event handling
    class MyEventHandler
    {
        public function __invoke(MyEvent $event)
        {
             echo 'handling event...';
             return $event; // optional
        }
    }

    // initiate event dispatcher
    $events = new Dispatcher(new Provider());

    // bind a callable with default priority 50 (0-100)
    $provider->attach(function(myEvent $event) {
        echo 'triggered...';
        return $event; // optional
    });

    // bind a invokable object with priority 80
    $provider->attach(new MyEventHandler(), 80);

    // fire the trigger, wil see output 'handling event...triggered...'
    $events->dispatch(new MyEvent());
    ```
- Event hierarchy

    Instead of using event name to trigger like many event libraries were doing. PSR-14 compliant event libraries now only support triggering with event object. By setting up a meaningful event object hierarchy, developers may achieve great flexibility in event handling.

    Listeners will **ONLY** handle the events (and their subclasses) configured with the event parameter.

    ```
    use Phoole\Event\Events\StoppableEvent;

    // my own event hierarchy top
    class MyEvent extends StoppableEvent
    {
    }

    // my user authentication event
    class MyAuthEvent extends MyEvent
    {
        protected $userInfo;

        public function __construct(array $userInfo)
        {
            $this->userInfo = $userInfo;
        }

        public function getUserInfo(): array
        {
            return $this->userInfo;
        }
    }

    $provider = new Provider();
    $events = new Dispatcher($provider);

    // attach a listener to the event hierarchy top
    $provider->attach(function(MyEvent $event) {
        echo 'Event '.get_class($event).' fired';
        return $event; // optional
    });

    // attach a listener for logging users
    $provider->attach(function(MyAuthEvent $event)) use ($logger) {
        $logger->info(sprintf("User '%s' logged", $event->getUserInfo()['name']));
        return $event; // optional
    });

    ...

    // upon user logged in, trigger the event
    // BOTH listeners will process THIS event
    $events->dispatcher(new MyAuthEvent($userInfo));
    ```
- Create a **listener class**

    A listener class may implement the `ListenerCapableInterface` and use `ListenerCapableTrait`.

    ```
    use Phoole\Event\ListenerCapableTrait;
    use Phoole\Event\ListenerCapableInterface;

    // my listener class
    class MyListener implements ListenerCapableInterface
    {
        use ListenerCapableTrait;

        // define on listener method
        public function MethodOne(MyEvent $event)
        {
             echo 'handling MyEvent in MethodOne...';
        }

        // define another listener method
        public function MethodTwo(MyEvent $event)
        {
            echo 'handling MyEvent in MethodTwo...';
        }

        // config this listener
        protected function eventsListening()
        {
            return [
                'MethodOne',
                ['MethodTwo', 80] // with priority 80
            ];
        }
    }

    // global dispatcher & provider
    $provider = new Provider();
    $events = new Dispatcher($provider);

    // set provider is enough
    $listener = new MyListener();
    $listener->setProvider($provider);

    // fire the event
    $events->dispatch(new MyEvent());
    ```

    Along with container library `phoole/di`, developer may not event worry about setting up dispatcher, provider or injecting the provider.

    ```
    use Phoole\Di\Container;

    // initiate the listener with dependencies injected
    $listener = Container::create(MyListener::class);

    // fire the event
    Container::events()->dispatch(new MyEvent());
    ```
- Triggering events in your classes

    `EventCapableInterface` and `EventCapableTrait` give developers the ability of triggering events in their classes.

    ```
    use Phoole\Event\EventCapableTrait;
    use Phoole\Event\EventCapableInterface;

    class MyEventCapable implements EventCapableInterface
    {
        use EventCapableTrait;

        public function myMethod()
        {
             $this->triggerEvent(new MyEvent());
        }
    }

    // global dispatcher & provider
    $provider = new Provider();
    $events = new Dispatcher($provider);

    $eventCapable = new MyEventCapable();
    $eventCapable->setDispatcher($dispatcher);

    // will trigger an event
    $eventCapable->myMethod();
    ```

    Along with container library `phoole/di`, developer may not event worry about setting up dispatcher, provider or injecting the dispatcher.

    ```
    // initiate object with dependencies injected
    $eventCapable = Container::create(MyEventCapable::class);

    // will trigger an event
    $eventCapable->myMethod();
    ```

Testing
-------

[](#testing)

```
$ composer test
```

Dependencies
------------

[](#dependencies)

- PHP &gt;= 7.2.0
- Phoole/base 1.\*

License
-------

[](#license)

- [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.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 ~6 days

Total

6

Last Release

2373d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3bae7d5f135e90fd05271574bfd04d4844169bd4c554eaa9e103e4af69267ffc?d=identicon)[phoole](/maintainers/phoole)

---

Top Contributors

[![phossa](https://avatars.githubusercontent.com/u/8499165?v=4)](https://github.com/phossa "phossa (8 commits)")[![phoole](https://avatars.githubusercontent.com/u/55728163?v=4)](https://github.com/phoole "phoole (1 commits)")

---

Tags

eventphoolephppsr-14swoolephpeventlibraryswoolephoole

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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