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

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

webiny/event-manager
====================

Webiny Event Manager Component

v1.6.1(8y ago)116.4k↑231.3%5MITPHPPHP ^7

Since Sep 20Pushed 8y ago8 watchersCompare

[ Source](https://github.com/Webiny/EventManager)[ Packagist](https://packagist.org/packages/webiny/event-manager)[ Docs](http://www.webiny.com/)[ RSS](/packages/webiny-event-manager/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (23)Used By (5)

Event Manager Component
=======================

[](#event-manager-component)

`EventManager` allows you to easily manage events throughout your application.

Install the component
---------------------

[](#install-the-component)

The best way to install the component is using Composer.

```
composer require webiny/event-manager
```

For additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/event-manager).

Usage
-----

[](#usage)

Accessing `EventManager` can be done in 2 ways. The preferable way is using `EventManagerTrait`, but you can also access it directly, using `EventManager::getInstance()`. Let's see a simple example of subscribing to an event called `some.event` with an instance of `YourHandler`:

```
class YourClass{
    use EventManagerTrait;

    public function index(){
        $this->eventManager()->listen('some.event')->handler(new YourHandler());
    }
}
```

You're done! You have just subscribed to an event and the moment `some.event` is fired, your handler will process it.

Event handlers
--------------

[](#event-handlers)

Now let's take a look at `YourHandler`. An event handler can be any class. `EventManager` will call `handle(Event $event)` method on your handler object, by default. You can, however, specify a method you want `EventManager` to call:

```
class YourHandler{

    public function customHandle(Event $event){
        // Do something with the $event...
    }

}

// Using your custom method
$this->eventManager()->listen('some.event')->handler(new YourHandler())->method('customHandle');
```

Besides using classes, you can also respond to an event using a callable:

```
// Using callable as event handler

$handler = function(Event $event){
    // Do something with the $event...
};

$this->eventManager()->listen('some.event')->handler($handler);

```

Firing events
-------------

[](#firing-events)

To fire a simple event use the following code:

```
$this->eventManager()->fire('some.event');
```

You can also pass some data when firing an event, which will be passed to every event listener:

```
$data = [
    'some' => 'data',
    'ip' => '192.168.1.10'
];

$this->eventManager()->fire('some.event', $data);
```

Any given data that is not an `Event` object, will be converted to generic `Event` object and your data will be accessible either by using array keys, or as object properties:

```
class YourHandler{

    public function customHandle(Event $event){
        // Access your data
        echo $event->some; // 'data'
        echo $event['some'] // 'data'
    }

}
```

If you want to use custom `Event` data types, refer to section [Custom event classes](#custom-event-classes)

Firing events using a wildcard
------------------------------

[](#firing-events-using-a-wildcard)

You can also use wildcard to fire multiple events at once. The following code will fire all events starting with `event.` and pass `$data` to each one of them:

```
$this->eventManager()->fire('event.*', $data);
```

Execution priority
------------------

[](#execution-priority)

`EventManager` allows you to specify an execution priority using `priority()` method. Here's an example:

```
// Specify a priority of execution for your event listeners
$this->eventManager()->listen('some.event')->handler(new YourHandler())->method('customHandler')->priority(250);
$this->eventManager()->listen('some.event')->handler(new YourHandler())->method('secondCustomHandler')->priority(400);
$this->eventManager()->listen('some.event')->handler(new YourHandler())->method('thirdCustomHandler');

// Now let's fire an event
$this->eventManager()->fire('some.event');
```

After firing an event, the event listeners will be ordered by priority in descending order. The higher the priority, the sooner the listener will be executed. In this example, the order of execution will be as follows: `secondCustomHandler`, `customHandler`, `thirdCustomHandler`. Default priority is `101`, so `thirdCustomHandler` is executed last.

Custom event classes
--------------------

[](#custom-event-classes)

When firing events, you can also pass your own event classes, that extend generic `Event` class. For example, you want to fire an event called `cms.page_saved` and pass the `Page` object. Of course, you could simply pass an array like `['page' => $pageObject]`, but for the sake of the example, let's pretend it's more complicated than that:

```
// Create your `PageEvent` class

class PageEvent extends Event{

    private $_page;

    public function __construct(Page $page){
        // Call constructor of parent Event class
        parent::__construct();

        // Set your page object
        $this->_page = $page;
    }

    public function getPage(){
        return $this->_page;
    }

}

// Fire an event

$pageEvent = new PageEvent($pageObject);

$this->eventManager()->fire('cms.page_saved', $pageEvent);

// In your handler, you can now access page object using $event->getPage()

class YourHandler{

    public function customHandle(PageEvent $event){
        $pageObject = $event->getPage();
    }

}
```

This is a simple example, but it shows the power of creating your own `Event` classes and add as much functionality to your events as you need.

Event subscriber
----------------

[](#event-subscriber)

Another cool feature of the `EventManager` is the ability to subscribe to multiple events at once. You will need to create a subscriber class implementing `EventSubscriberInterface`:

```
class PageEventSubscriber implements EventSubscriberInterface {
    use EventManagerTrait;

    /**
     * Handle page creation event
     */
    public function onPageCreated($event)
    {
        //
    }

    /**
     * Handle page update
     */
    public function onPageUpdated($event)
    {
        //
    }

    /**
     * Register the listeners for the subscriber.
     */
    public function subscribe()
    {
        $this->eventManager()->listen('cms.page_created')->handler($this)->method('onPageCreated');
        $this->eventManager()->listen('cms.page_updated')->handler($this)->method('onPageUpdated');
    }

}

// Subscriber to multiple events using your new subscriber class
$this->eventManager()->subscribe($subscriber);
```

There are situations when you need to temporarily disable EventManager. For example, deleting a huge portion of files that are not directly related to the application (local cache files) does not require firing all of related events. In this case use the following methods:

```
// Disabling EventManager
$this->eventManager()->disable();

// Do some work that would fire loads of unnecessary events...

// Enabling EventManager
$this->eventManager()->enable();
```

Resources
---------

[](#resources)

To run unit tests, you need to use the following command:

```
$ cd path/to/Webiny/Component/EventManager/
$ composer.phar install
$ phpunit

```

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity73

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

Recently: every ~5 days

Total

22

Last Release

3200d ago

PHP version history (3 changes)v1.0.0PHP &gt;=5.4.0

v1.2.1PHP &gt;=5.5.9

1.5.x-devPHP ^7

### Community

Maintainers

![](https://www.gravatar.com/avatar/4440afa738ed146b05c06073a90345e0464c4f4d042b039532d881ca24859d77?d=identicon)[SvenAlHamad](/maintainers/SvenAlHamad)

---

Top Contributors

[![SvenAlHamad](https://avatars.githubusercontent.com/u/3808420?v=4)](https://github.com/SvenAlHamad "SvenAlHamad (19 commits)")

---

Tags

eventsevent manager

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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.0k526.1M158](/packages/doctrine-event-manager)[psr/event-dispatcher

Standard interfaces for event handling.

2.3k667.1M1.4k](/packages/psr-event-dispatcher)[laminas/laminas-eventmanager

Trigger and listen to events within a PHP application

1.0k72.5M255](/packages/laminas-laminas-eventmanager)[simshaun/recurr

PHP library for working with recurrence rules

1.6k17.2M53](/packages/simshaun-recurr)[chelout/laravel-relationship-events

Missing relationship events for Laravel

5272.5M17](/packages/chelout-laravel-relationship-events)[tormjens/eventy

The WordPress filter/action system in Laravel

439951.1k24](/packages/tormjens-eventy)

PHPackages © 2026

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