PHPackages                             mikemix/eventdispatcher - 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. mikemix/eventdispatcher

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

mikemix/eventdispatcher
=======================

Easily attach to ZF2 events

1.0.2(12y ago)223MITPHPPHP &gt;=5.3.23

Since Jun 11Pushed 11y agoCompare

[ Source](https://github.com/mikemix/eventdispatcher)[ Packagist](https://packagist.org/packages/mikemix/eventdispatcher)[ RSS](/packages/mikemix-eventdispatcher/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

EventDispatcher
===============

[](#eventdispatcher)

This module is old, crappy and unmaintained, so please don't use it :)
======================================================================

[](#this-module-is-old-crappy-and-unmaintained-so-please-dont-use-it-)

Easily attach listeners to ZF2's MVC events.

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

[](#installation)

1. Add `"mikemix/eventdispatcher": "1.*"` to your composer.json file
2. Run `php composer.phar self-update && php composer.phar update`
3. Add module `EventDispatcher` to your application modules in the `application.config.php` file
4. Copy file `vendor/mikemix/eventdispatcher/config/event_dispatcher.global.php.dist` to the `config/autoload/event_dispatcher.global.php`

Congratulations. You are done and the library has been successfully installed (hope so). To subscribe to a mvc event, it is as simple as adding a name of your listener service name to the `event_dispatcher.global.php` file. The name must be recognized by the service manager.

Example configuration
---------------------

[](#example-configuration)

File `config/autoload/event_dispatcher.config.php`

```
return array(
    'event_dispatcher' => array(
        'dispatch' => array(
            // dispatch listeners here
            'myDispatchListener'       #  array(
            // dispatch.error listeners here
        ),
        'finish' => array(
            // finish listeners here
        ),
        'render' => array(
            // render listeners here
        ),
        'render.error' => array(
            // render.error listeners here
        ),
        'route' => array(
            // route listeners here
        ),
    ),
);
```

File `module/Application/config/module.config.php`

```
// ...
'service_manager' => array(
    // ...

    'invokables' => array(
        'myDispatchListener' => 'Application\Listener\DispatchListener',
    ),
),
```

File `module/Application/src/Application/Listener/DispatchListener.php`. For your convienience and type hinting in the editor of your choice, you can make listener implement the ListenerInterface interface, but you are not obliged to. Just make sure an `onEvent()` method is callable.

```
