-
Notifications
You must be signed in to change notification settings - Fork 0
/
openswoole.php
92 lines (79 loc) · 2.55 KB
/
openswoole.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
class OpenswooleApp
{
public function __construct(string $address = '127.0.0.1', int $port = 9501, int $mode = OpenSwoole\Server::POOL_MODE, int $sock_type = OpenSwoole\Constant::SOCK_TCP)
{
global $server_config;
if (isset($server_config['cli'])) {
$server_config['addr'] = $server_config['cli']['address'];
$server_config['port'] = $server_config['cli']['port'];
$server_config['mode'] = $mode;
$server_config['type'] = $sock_type;
} else {
$server_config['addr'] = $address;
$server_config['port'] = $port;
$server_config['mode'] = $mode;
$server_config['type'] = $sock_type;
}
}
protected function createServer(string $server_type): void
{
global $server_config;
$server_config['server'] = new $server_type($server_config['addr'], $server_config['port'], $server_config['mode'], $server_config['type']);
}
public function getConfig(): array|null
{
global $server_config;
return ['address' => $server_config['addr'], 'port' => $server_config['port'], 'mode' => $server_config['mode'], 'type' => $server_config['type']];
}
public function UdpTcp(): UdpTcp
{
require_once 'app/protocol/udp-tcp.php';
return new UdpTcp();
}
public function Http(): Http
{
require_once 'app/protocol/http.php';
return new Http();
}
public function WebSocket(): WebSocket
{
require_once 'app/protocol/websocket.php';
return new WebSocket();
}
public function Event(): Event
{
require_once 'app/schedule/event.php';
return new Event();
}
public function Timer(): Timer
{
require_once 'app/schedule/timer.php';
return new Timer();
}
public function Coroutine(): Coroutine
{
require_once 'app/php-coroutine/coroutine.php';
return new Coroutine();
}
public function CoSystem(): CoSystem
{
require_once 'app/php-coroutine/coroutine-system.php';
return new CoSystem();
}
public function CoChannel(): CoChannel
{
require_once 'app/php-coroutine/coroutine-channel.php';
return new CoChannel();
}
public function CoWaitGroup(): CoWaitGroup
{
require_once 'app/php-coroutine/coroutine-wait-group.php';
return new CoWaitGroup();
}
public function CoServer(): CoServer
{
require_once 'app/php-coroutine/coroutine-server.php';
return new CoServer();
}
}