tioncico / event-hook
Installs: 47
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:l
Requires
- easyswoole/component: ^2.0
This package is auto-updated.
Last update: 2025-03-25 13:30:13 UTC
README
hook事件组件 借鉴tp5写的hook事件
$eventHook = EventHook::getInstance(); //闭包函数 $result = $eventHook->add('test',function ($a,$b,$c){ $this->assertEquals($a,1); $this->assertEquals($b,2); $this->assertEquals($c,3); return [$a,$b,$c]; }); $this->assertTrue(!!$result); //传入类名 $result = $eventHook->add('test',Test::class); $this->assertTrue(!!$result); //传入类名+方法名数组 $result = $eventHook->add('test',[Test::class,'test']); $this->assertTrue(!!$result); //传入一个类 $result = $eventHook->add('test',new TestClass()); $this->assertTrue(!!$result); $result = $eventHook->listen('test',false,1,2,3); foreach ($result as $value){ $this->assertEquals($value,[1,2,3]); }