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

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

heybigname/event-dispatcher
===========================

Event Dispatcher with a focus on Domain Events

1.1.2(11y ago)5913.1k↑44.4%3[1 PRs](https://github.com/heybigname/event-dispatcher/pulls)1MITPHPPHP &gt;=5.4.0CI failing

Since Jun 12Pushed 11y ago12 watchersCompare

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

READMEChangelogDependencies (5)Versions (6)Used By (1)

Domain Event Dispatcher
=======================

[](#domain-event-dispatcher)

[![Latest Stable Version](https://camo.githubusercontent.com/a67a2e661f4175811b676a46a3509063bfef22579abf7ce9e2cb3a0f28947084/68747470733a2f2f706f7365722e707567782e6f72672f6865796269676e616d652f6576656e742d646973706174636865722f76657273696f6e2e706e67)](https://packagist.org/packages/heybigname/event-dispatcher)[![License](https://camo.githubusercontent.com/c7a407ae4c2eec30049e9deea6b9adf56a1163b1a130867bcd39c21d100fbfe9/68747470733a2f2f706f7365722e707567782e6f72672f6865796269676e616d652f6576656e742d646973706174636865722f6c6963656e73652e706e67)](https://packagist.org/packages/heybigname/event-dispatcher)[![Build Status](https://camo.githubusercontent.com/699d69f5f8842de37761912bccc97c784438c03b2d27348598d3a8d7172eda23/68747470733a2f2f7472617669732d63692e6f72672f6865796269676e616d652f6261636b75702d6d616e616765722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/heybigname/backup-manager)[![Coverage Status](https://camo.githubusercontent.com/3f844a31d8393a6507f9481f3b0009b0d839dab016bb7c36041b77b8afc2d3df/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6865796269676e616d652f6576656e742d646973706174636865722e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/heybigname/event-dispatcher?branch=master)[![Total Downloads](https://camo.githubusercontent.com/3bcdf83a84acefe7b094ebbb32b05fa105bd0793527965d6d6a96af85f72ee04/68747470733a2f2f706f7365722e707567782e6f72672f6865796269676e616d652f6576656e742d646973706174636865722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/heybigname/event-dispatcher)

An Event Dispatcher built with a focus on Domain Events.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Integrations](#integrations)
    - [Laravel](#laravel)
- [How It Works](#how-it-works)
    - [Event](#event)
    - [Listener](#listener)
    - [Listening](#listening)
    - [Lazy Listening](#lazy-listening)
    - [Dispatching Multiple Events](#dispatching-multiple-events)
- [Maintainers](#maintainers)
- [License](#license)

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

[](#installation)

Run the command below to install via Composer

```
composer require heybigname/event-dispatcher
```

Integrations
------------

[](#integrations)

Although this package is completely framework agnostic, it does have integrations with framework(s). Currently only Laravel 4.x is included, but if requested others can be added.

### Laravel

[](#laravel)

To install into a Laravel project, first do the composer install then add the following class to your `config/app.php` service providers list.

```
'BigName\EventDispatcher\Integrations\Laravel\ServiceProvider',
```

That's all it takes for the Laravel integration. Now it's possible to inject or make a Dispatcher like this:

```
use BigName\EventDispatcher\Dispatcher;

class RegisterMemberHandler implements Handler
{
    private $dispatcher;

    public function __construct(Dispatcher $dispatcher)
    {
        $this->dispatcher = $dispatcher;
    }
}
```

```
$dispatcher = App::make('BigName\EventDispatcher\Dispatcher');
```

How It Works
------------

[](#how-it-works)

### Event

[](#event)

In your domain you'll create an event, for let's say when a new member has been registered. Lets call this event `MemberWasRegistered`. This event will hold the necessary information for the listener to fulfill it's job. You have complete freedom about which arguments it takes, since you'll be the one passing them in. In some ways this event is a `Data Transfer Object` (DTO).

For example:

```
