1. Go to this page and download the library: Download yzh52521/webman-event 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/ */
namespace app\events;
class Test
{
public $data = [];
public function __construct($data)
{
$this->data = $data;
}
}
namespace app\listeners;
use app\events\Test;
class TestListeners
{
public function __construct()
{
}
/**
* 处理事件
* @return void
*/
public function handle(Test $event)
{
// 控制台打印
var_dump('listener');
var_dump($event->data);
}
}
namespace app\subscribes;
use app\events\Test;
class TestSubscribe
{
public function handleTest(Test $event)
{
var_dump('subscribe');
var_dump($event);
}
public function subscribe($events)
{
$events->listen(
Test::class,
[TestSubscribe::class, 'handleTest']
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.