-
Notifications
You must be signed in to change notification settings - Fork 0
/
EasySwooleEvent.php
54 lines (47 loc) · 1.63 KB
/
EasySwooleEvent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Created by PhpStorm.
* User: yf
* Date: 2018/1/9
* Time: 下午1:04
*/
namespace EasySwoole;
use App\Socket\WebSocket\Logic\RoomRedis;
use App\Socket\WebSocket\Parser;
use App\Utility\Redis;
use \EasySwoole\Core\AbstractInterface\EventInterface;
use EasySwoole\Core\Component\Di;
use EasySwoole\Core\Swoole\EventHelper;
use EasySwoole\Core\Swoole\Memory\TableManager;
use \EasySwoole\Core\Swoole\ServerManager;
use \EasySwoole\Core\Swoole\EventRegister;
use \EasySwoole\Core\Http\Request;
use \EasySwoole\Core\Http\Response;
Class EasySwooleEvent implements EventInterface {
public static function frameInitialize(): void
{
// TODO: Implement frameInitialize() method.
date_default_timezone_set('Asia/Shanghai');
}
public static function mainServerCreate(ServerManager $server,EventRegister $register): void
{
//注册WebSocket解析规则
EventHelper::registerDefaultOnMessage($register,Parser::class);
//注册onClose事件
$register->add($register::onClose, function (\swoole_server $server, $fd, $reactorId) {
//清除Redis fd的全部关联
RoomRedis::close($fd);
});
// 注册
Di::getInstance()->set('REDIS',new Redis(Config::getInstance()->getConf('REDIS')));
//Di::getInstance()->set('ROOM_TABLE',TableManager::getInstance());
}
public static function onRequest(Request $request,Response $response): void
{
// TODO: Implement onRequest() method.
}
public static function afterAction(Request $request,Response $response): void
{
// TODO: Implement afterAction() method.
}
}