PHP 事件类 YurunEvent

MIT
PHP 查看源码»
跨平台
2017-08-11
宇润

YurunEvent

PHP事件类,支持全局事件和类中事件。

Composer

"require": {
    "yurunsoft/yurun-event" : "dev-master"
}

代码实例

全局事件

// 监听事件
Event::on('test', function($e){
	var_dump('trigger test', $e);
	$e['value'] = 'yurun';
});

// 一次性事件
Event::once('test1', function($e){
	var_dump('trigger test', $e);
	$e['value'] = $e['message'];
});

// 触发事件
Event::trigger('test', array('message'=>'666', 'value'=>&$value));

类中事件

class Test
{
	use ClassEvent;

	private $value;

	public function setValue($value)
	{
		$this->value = $value;
		$this->trigger('changeValue', array('value'=>$value));
	}
}

$test = new Test;
// 绑定事件
$test->on('changeValue', function($e){
	echo 'changeValue1:', $e['value'], PHP_EOL;
});
// 一次性事件
$test->once('changeValue', function($e){
	echo 'changeValue2:', $e['value'], PHP_EOL;
});
$test->setValue(123);
$test->setValue(456);

更详细的代码请至Demo目录。

加载中

评论(1)

战神悟空
战神悟空
观察者模式

暂无资讯

暂无问答

Fundamental Components Of An Event-Driven Archi...

Fundamental Components Of An Event-Driven Architecture http://www.giocc.com/fundamental-components-of-an-event-driven-architecture.html published: April 9, 2012 My favorite type...

2013/10/26 00:22
20
0
晚上躺在星空下聊天,那时候的暑假真的是美好而又单纯Back In Summertime

http://t.163.com/event/info/eventId/-2664187554964249601 http://t.163.com/event/info/eventId/-4698009606809035037 http://t.163.com/event/info/eventId/-4421262430386300338 http:/...

2013/09/13 13:50
16
0
MySQL之事件学习整理

在使用事件之前需要激活MySQL的事件调度器(Event Scheduler),激活方式如下: set global event_scheduler=1 或者 set global event_scheduler=on 然后我们可以查看调度器是否已经开启: ...

2012/04/25 16:16
131
0
javafx官方文档学习之Event体系理解

我的博文小站:http://www.xby1993.net 最新资讯都在那里。 主要讲javafx.event package: javafx.event Interface EventTarget 而 EventDispatchChain buildEventDispatchChain(EventDispat...

2013/12/14 00:00
211
0
旋律很熟悉,虽然想听点不一样的旋律Untitled--Simple Plan很有味道

http://t.163.com/event/info/eventId/-2664187554964249601 http://t.163.com/event/info/eventId/-4698009606809035037 http://t.163.com/event/info/eventId/-4421262430386300338 http:/...

2013/09/13 13:51
21
0
Snakes And Ladders--Scouting for Girls 清新,干净, C...

http://t.163.com/event/info/eventId/-2664187554964249601 http://t.163.com/event/info/eventId/-4698009606809035037 http://t.163.com/event/info/eventId/-4421262430386300338 http:/...

2013/09/13 13:52
11
0
MySql数据库 事件以及函数操作

- 查看事件调度器是否开启 ```sql show variables like 'event_scheduler'; ``` - 开启事件调度器 ```sql  set global event_scheduler = on; ``` - 查询所有时间的状态 ```sql SELECT EVEN...

04/19 11:58
19
0
libevent学习文档(三)working with event

Events have similar lifecycles. Once you call a Libevent function to set up an event and associate it with an event base, it becomes initialized. At this point, you can add, whi...

2016/08/10 11:34
7
0
libevent学习文档(二)eventbase相关接口和参数

Setting up a default event_base The event_base_new() function allocates and returns a new event base with the default settings. It examines the environment variables and returns...

2016/08/10 11:35
16
0

没有更多内容

加载失败,请刷新页面

返回顶部
顶部