radnan/rdn-event 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

radnan/rdn-event

最新稳定版本:v1.0.0

Composer 安装命令:

composer require radnan/rdn-event

包简介

Zend Framework 2 event listener manager

README 文档

README

The RdnEvent ZF2 module provides a service locator for event listeners.

How to install

  1. Use composer to require the radnan/rdn-event package:

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

    <?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.

<?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.

Let's create a hello world listener inside our App module:

1. Create listener class

Create the class App\Listener\HelloWorld by extending RdnEvent\Listener\AbstractListener:

<?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:

<?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:

<?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.

统计信息

  • 总下载量: 19.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-12-27