Metrics
0
Watch 8 Star 19 Fork 3

宇润 / YurunEventPHPMIT

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
PHP事件类,支持全局事件和类中事件。程序员Q群:74401592 spread retract

https://github.com/Yurunsoft/YurunEvent

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

YurunEvent

PHP事件类,支持全局事件和在类中定义和使用事件。

Composer

"require": {
    "yurunsoft/yurun-event" : "~2.0"
}

代码实例

全局事件

// 监听事件
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目录。

Comments ( 4 )

You need to Sign in for post a comment

PHP
1
https://gitee.com/yurunsoft/yurunevent.git
git@gitee.com:yurunsoft/yurunevent.git

Help Search