systream/event-dispatcher 问题修复 & 功能扩展

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

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

systream/event-dispatcher

Composer 安装命令:

composer require systream/event-dispatcher

包简介

Observer for events

README 文档

README

Observer for events

Usage Examples

Installation

You can install this package via packagist.org with composer.

composer require systream/event-dispatcher

composer.json:

"require": {
    "systream/event-dispatcher": "1.*"
}

This library requires php 5.6 or higher, but also works on php 5.4.

Subscribe to event

$eventDispatcher = new EventDispatcher();

$subscription = new EventDispatcher\Subscription('nameOfEvent', function (EventInterface $event) {
	// do stuff here
});
$eventDispatcher->subscribe($subscription);

Fire an event

$eventDispatcher = new EventDispatcher();
$eventDispatcher->emit(new EventDispatcher\Event('nameOfEvent'));

Stop Propagation

$eventDispatcher = new EventDispatcher();

$subscription = new EventDispatcher\Subscription('fooBar', function (EventDispatcher\EventInterface $event) {
	$event->stopPropagation();
});
$eventDispatcher->subscribe($subscription);

$subscription2 = new EventDispatcher\Subscription('fooBar', function (EventDispatcher\EventInterface $event) {
	// do stuff here
});
$eventDispatcher->subscribe($subscription2);

$eventDispatcher->emit(new EventDispatcher\Event('fooBar'));

In this case the second subscription won't be invoked.

Custom events

The only thing you need to do is that implementing the EventInterface

class MyCustomEvent extends AbstractEvent implements EventInterface
{

	/**
	 * @var string
	 */
	protected $key = 'order.save';

	/**
	 * @var Order
	 */
	protected $order;

	/**
	 * @param string $key
	 */
	public function __construct(Order $order)
	{
		$this->order = $order;
	}

	/**
	 * @return Order
	 */
	public function getOrder()
	{
		return $this->order;
	}
}

...

$eventDispatcher = new EventDispatcher();
$subscription = new EventDispatcher\Subscription('nameOfEvent', function (OrderEvent $event) {
	$order = $orderEvent->getOrder();
	// do stuff
});
$eventDispatcher->subscribe($subscription);

Custom Subscriptions

The only thing you need to do is that implementing the SubscriptionInterface

Test

Build Status

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固