2017 © Pedro Peláez
 

library rdn-event

Zend Framework 2 event listener manager

image

radnan/rdn-event

Zend Framework 2 event listener manager

  • Thursday, January 2, 2014
  • by radnan
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4,542 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 12 % Grown

The README.md

RdnEvent

The RdnEvent ZF2 module provides a service locator for event listeners., (*1)

How to install

  1. Use composer to require the radnan/rdn-event package:, (*2)

    $ composer require radnan/rdn-event:1.*
    
  2. Activate the module by including it in your application.config.php file:, (*3)

    <?php
    
    return array(
       'modules' => array(
           'RdnEvent',
           // ...
       ),
    );
    

How to use

Simply configure your event listeners with the RdnEvent\Listener\ListenerManager service locator using the rdn_event_listeners configuration option. Listeners are any class that implements the Zend\EventManager\ListenerAggregateInterface interface., (*4)

<?php

return array(
    'rdn_event_listeners' => array(
        'invokables' => array(),
        'factories' => array(),
    ),
);

How to create listeners

Create your listeners inside your module, register them with the event listener service locator, and finally attach the listener by including it in the rdn_event[listeners] configuration option., (*5)

Let's create a hello world listener inside our App module:, (*6)

1. Create listener class

Create the class App\Listener\HelloWorld by extending RdnEvent\Listener\AbstractListener:, (*7)

<?php

namespace App\Listener;

use RdnConsole\Listener\AbstractListener;
use Zend\EventManager\EventInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\MvcEvent;

class HelloWorld extends AbstractListener
{
    public function attach(EventManagerInterface $events)
    {
        $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'execute'));
    }

    public function execute(EventInterface $event)
    {
        var_dump('Hello World!');
    }
}

2. Register listener with service locator

Place the following in your module.config.php file:, (*8)

<?php

return array(
    'rdn_event_listeners' => array(
        'invokables' => array(
            'App:HelloWorld' => 'App\Listener\HelloWorld',
        ),
    ),
);

3. Attach the listener to the event manager

Now, place the following in your module.config.php file:, (*9)

<?php

return array(
    'rdn_event' => array(
        'listeners' => array(
            'App:HelloWorld',
        ),
    ),
);

That's it! The module will fetch the listener from the service locator and attach it to the application's event manager., (*10)

The Versions

02/01 2014

dev-master

9999999-dev

Zend Framework 2 event listener manager

  Sources   Download

MIT

The Requires

 

by Avatar radnan

zf2 zend event listener

27/12 2013

v1.0.0

1.0.0.0

Zend Framework 2 event listener manager

  Sources   Download

MIT

The Requires

 

by Avatar radnan

zf2 zend event listener