PHP code example of tioncico / event-hook

1. Go to this page and download the library: Download tioncico/event-hook library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tioncico / event-hook example snippets



$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]);
}