PHPackages                             phossa/phossa-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. [Framework](/categories/framework)
4. /
5. phossa/phossa-event

ActiveLibrary[Framework](/categories/framework)

phossa/phossa-event
===================

A event management library for PHP

1.0.7(9y ago)142MITPHPPHP &gt;=5.4.0

Since Nov 2Pushed 6y ago1 watchersCompare

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

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

phossa-event \[ABANDONED\]
==========================

[](#phossa-event-abandoned)

[![Build Status](https://camo.githubusercontent.com/e0a1d27274202ff790460c5da57dc9794b3b9d31200a8fb58a7e07c36ccf7cc5/68747470733a2f2f7472617669732d63692e6f72672f70686f7373612f70686f7373612d6576656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phossa/phossa-event)[![Latest Stable Version](https://camo.githubusercontent.com/6017593fdf55a415ac37f5ee2c0ecfaaa38fbe64062d06531c0d04859895cfc7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f70686f7373612f70686f7373612d6576656e742e7376673f7374796c653d666c6174)](https://packagist.org/packages/phossa/phossa-event)[![License](https://camo.githubusercontent.com/fe1cbff1c1bee8e0213e628b9d265a021bafdab98b2997d437a1277d635324ae/68747470733a2f2f706f7365722e707567782e6f72672f70686f7373612f70686f7373612d6576656e742f6c6963656e7365)](http://mit-license.org/)

**See new lib at [phoole/event](https://github.com/phoole/event)**Introduction
------------------------------------------------------------------------------

[](#see-new-lib-at-phooleeventintroduction)

Phossa-event is an event management library for PHP. It decoupled from any packages other than the `phossa/phossa-shared`. It requires PHP5.4 only.

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

[](#installation)

Install via the `composer` utility.

```
composer require "phossa/phossa-event=1.*"

```

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

```
{
    "require": {
       "phossa/phossa-event": "1.*"
    }
}
```

Simple `EventDispatcher`
------------------------

[](#simple-eventdispatcher)

Simple event dispatching using `Phossa\Event\EventDispatcher`

- Simple usage

    ```
    $dispatcher = new EventDispatcher();

    // bind event 'user.login' to a callable
    $dispatcher->on('user.login', function(Event $evt) {
        // ...
    });

    // trigger the 'user.login' event, passing data
    $dispatcher->trigger('user.login', [ 'user' => $user ]);
    ```

    or use statically (global dispatching)

    ```
    // bind event with priority 60 (0 - 100, high # higher priority)
    EventDispatcher::on('user.login', function(Event $evt) {
        // ...
    }, 60);

    // trigger the 'user.login' event
    EventDispatcher::trigger('user.login', [ 'user' => $user ]);
    ```
- Trigger for limited times

    ```
    // bind event for once
    $dispatcher->one('user.login', function(Event $evt) {
        // ...
    });

    // allow 3 times
    $dispatcher->many('user.tag', 3, function(Event $evt) {
        // ...
    });
    ```
- Event globbing

    ```
    // globbing
    $dispatcher->on('user.*', function(Event $evt) {
        //...
    });
    ```
- Detach events

    ```
    // detach
    $dispatcher->off('user.*');
    ```
- Monitoring PHP errors

    Execute a callable when PHP error happens.

    ```
    // callable returns bool
    $dispatcher->error(function($errno, $errstr, $errfile, $errline) {
        // ...
        return true;
    });
    ```
- Execute a callable when script finishes

    ```
    // run this after script ends
    $dispatcher->ready(function() {
        // ...
    });
    ```

Full-fledged `EventManager`
---------------------------

[](#full-fledged-eventmanager)

Complex event management using `Phossa\Event\EventManager` with full fledge support for event listener, event subject, local event manager and global event manageretc.

- Event listener

    ```
    use Phossa\Event\Interfaces;

    class MyListener implements Interfaces\EventListenerInteface
    {
        /*
         * Get events and callables MyListener listens to
         */
        public function getEventsListening()
        {
            return array(
                'eventName1' => 'method1', // method1 of $this
                'eventName2' => array('method2', 20), // priority 20
                'eventName3' => array( // multiple callables
                    [ 'method3', 70 ],
                    [ 'method4', 50 ]
                )
            );
        }
    }

    $listener = new MyListener();
    ```
- Event manager

    ```
    // create an event manager
    $evtManager = new Event\EventManager();

    // attach a listener object
    $evtManager->attachListener($listener);

    // attach a callable directly to 'oneSpecialEvent'
    $callable = function(Event\Event $evt) {
        ...
    };
    $evtManager->attachListener($callable, 'oneSpecialEvent');

    // detach a callable
    $evtManager->detachListener($callable);
    ```
- The event-aware subject

    ```
    use Phossa\Event\Interfaces;

    class MyEventAware implements Interfaces\EventAwareInterface
    {
        // add setEventManager() and triggerEvent()
        use Interfaces\EventAwareTrait;

        ...
    }

    $subject = new MyEventAware();
    ```
- Combine together

    ```
    // set manager to event-aware subject
    $subject->setEventManager($evtManager);

    // trigger event
    $subject->triggerEvent('eventName2');
    ```
- Event globbing

    Able to listen to all events by using '*' or 'event*'.

    ```
    use Phossa\Event\Interfaces\EventListenerInterface;

    class Listener implements EventListenerInterface
    {
        public function getEventsListening()
        {
            return [
                'evtTest1' => 'testC',
                'evtTest2' => [ 'testD', 20 ],
                'evtTest3' => [
                    [ 'testA', 70 ],
                    [ 'testB', 50 ]
                ],
                // globbing
                'evt*' => 'bingo',
                'evtTest*' => 'bingo2',
                '*' => 'wow',
            ];
        }
    }
    ```
- Event management for static classes.

    The static listener class,

    ```
    use Phossa\Event\Interfaces;

    class StaticListener implements Interfaces\EventListenerStaticInteface
    {
        /*
         * Get events and callables StaticListener listens to
         */
        public static function getEventsListening()
        {
            return array(
                'eventName1' => 'method1', // method1 of $this
                'eventName2' => array('method2', 20), // priority 20
                'eventName3' => array( // multiple callables
                    [ 'method3', 70 ],
                    [ 'method4', 50 ]
                )
            );
        }
    }
    ```

    The static subject class to use events,

    ```
    use Phossa\Event\Interfaces;

    class StaticEventAware implements Interfaces\EventAwareStaticInterface
    {
        // add setEventManager() and triggerEvent()
        use Interfaces\EventAwareStaticTrait;

        ...
    }
    ```

    The static subject class trigger events as follows,

    ```
    // create an event manager/dispatcher
    $evtManager = new Event\EventManager();

    // attach a static listener class
    $evtManager->attachListener(StaticListener::CLASS);

    // set manager/dispatcher to event-aware static subject class
    StaticEventAware::setEventManagerStatically($evtManager);

    // trigger event by the static subject class
    StaticEventAware::triggerEventStatically('eventName2');
    ```
- Composite event manager

    Able to use composite event manager as follows,

    ```
    use Phossa\Event;

    // global event manager
    $global_manager = new Event\EventManager();
    $global_manager->attachListener($some_global_event_listener);

    // local event manager
    $local_manager  = new Event\Variation\EventManagerComposite();
    $local_manager->attachListener($local_listener);

    // allow local event manager dispatch events to global event manager
    $local_manager->setOtherManager('global', $global_manager);

    // the event aware subject
    $subject = new MyEventAware();

    // set event manager
    $subject->setEventManager($local_manager);

    // fire up an event, will look into event handling queue from both
    // $local_manager and $global_manager
    $subject->triggerEvent('some_event');
    ```
- Immutable event manager

    ```
    use Phossa\Event;

    // low-level manager to hide
    $_evtManager = new EventManager();
    $_evtManager->attachListener(...);
    ...

    // expose an immutable event managet to user
    $evtManager = new Variation\ImmutableEventManager($_evtManager);

    // cause an exception
    $evtManager->detachListener( ... );
    ```
- Shareable event manager, a single copy of global manager and lots of local managers.

    ```
    // get global copy by using static method `getInstance()`
    $globalEventManager = ShareableEventManager::getInstance();

    // normal event managers
    $localEventManager  = new ShareableEventManager();

    // is this the global copy?
    if ($evtManager->isShareable()) {
        ...
    } else {
        ...
    }
    ```

Features
--------

[](#features)

- Supports PHP 5.4+, PHP 7.0+, HHVM.
- PHP7 ready for return type declarations and argument type declarations.
- PSR-1, PSR-2, PSR-4 compliant.
- Decoupled packages can be used seperately without the framework.

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

[](#dependencies)

- PHP &gt;= 5.4.0
- phossa/phossa-shared &gt;= 1.0.8

License
-------

[](#license)

[MIT License](http://mit-license.org/)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Recently: every ~29 days

Total

6

Last Release

3636d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

eventframeworkphossa

### Embed Badge

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

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

###  Alternatives

[pestphp/pest-plugin-stressless

Stressless plugin for Pest

67792.6k16](/packages/pestphp-pest-plugin-stressless)[nimbly/syndicate

A powerful queue and pubsub message publisher and consumer framework.

304.2k](/packages/nimbly-syndicate)

PHPackages © 2026

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