-
Notifications
You must be signed in to change notification settings - Fork 0
/
Api.php
95 lines (80 loc) · 1.78 KB
/
Api.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
93
94
95
<?php
/**
* Created by PhpStorm.
* User: fuerm
* Date: 18/8/27 027
* Time: 21:29
*/
class Api
{
const REQUEST_TYPE_SWOOLE = 'swoole';
const REQUEST_TYPE_YARS = 'yars';
const REQUEST_METHOD_GET = 'GET';
const REQUEST_METHOD_POST = 'POST';
private $type = self::REQUEST_TYPE_SWOOLE;
private $spare = self::REQUEST_TYPE_YARS;
private $host = '';
private $port = 9800;
private $keep = true;
/**
* Api constructor.
* @param string $host
* @param int $port
* @param string $type
* @param string $spare
* @param bool $keep
*/
public function __construct($host, $port = 9800, $type = self::REQUEST_TYPE_SWOOLE, $spare = self::REQUEST_TYPE_YARS, $keep = true)
{
$this->host = $host;
$this->port = $port;
$this->type = $type;
$this->spare = $spare;
$this->keep = $keep;
}
/**
* @param string $type
*/
public function setType($type)
{
$this->type = $type;
}
/**
* @param string $spare
*/
public function setSpare($spare)
{
$this->spare = $spare;
}
/**
* @param string $host
*/
public function setHost($host)
{
$this->host = $host;
}
/**
* @param int $port
*/
public function setPort($port)
{
$this->port = $port;
}
/**
* @param bool $keep
*/
public function setKeep($keep)
{
$this->keep = $keep;
}
public function doRequest(Request $request)
{
return new Response(null, '');
}
public static function factory($key)
{
/** @var array $config */
$config = C($key);
return new static($config['host'], $config['port'], $config['type'], $config['keep']);
}
}