1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlibabaCloud\Client\Filter; |
4
|
|
|
|
5
|
|
|
use AlibabaCloud\Client\Exception\ClientException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class HttpFilter |
9
|
|
|
* |
10
|
|
|
* @package AlibabaCloud\Client\Filter |
11
|
|
|
*/ |
12
|
|
|
class HttpFilter |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param $host |
16
|
|
|
* |
17
|
|
|
* @return string |
18
|
|
|
* |
19
|
|
|
* @throws ClientException |
20
|
|
|
*/ |
21
|
48 |
|
public static function host($host) |
22
|
|
|
{ |
23
|
48 |
|
if (!is_string($host)) { |
24
|
3 |
|
throw new ClientException( |
25
|
3 |
|
'Host must be a string', |
26
|
|
|
\ALIBABA_CLOUD_INVALID_ARGUMENT |
27
|
3 |
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
45 |
|
if ($host === '') { |
31
|
3 |
|
throw new ClientException( |
32
|
3 |
|
'Host cannot be empty', |
33
|
|
|
\ALIBABA_CLOUD_INVALID_ARGUMENT |
34
|
3 |
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
42 |
|
return $host; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param $scheme |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
* |
45
|
|
|
* @throws ClientException |
46
|
|
|
*/ |
47
|
32 |
|
public static function scheme($scheme) |
48
|
|
|
{ |
49
|
32 |
|
if (!is_string($scheme)) { |
50
|
1 |
|
throw new ClientException( |
51
|
1 |
|
'Scheme must be a string', |
52
|
|
|
\ALIBABA_CLOUD_INVALID_ARGUMENT |
53
|
1 |
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
31 |
|
if ($scheme === '') { |
57
|
1 |
|
throw new ClientException( |
58
|
1 |
|
'Scheme cannot be empty', |
59
|
|
|
\ALIBABA_CLOUD_INVALID_ARGUMENT |
60
|
1 |
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
30 |
|
return $scheme; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $body |
68
|
|
|
* |
69
|
|
|
* @return mixed |
70
|
|
|
* @throws ClientException |
71
|
|
|
*/ |
72
|
7 |
|
public static function body($body) |
73
|
|
|
{ |
74
|
7 |
|
if (!is_string($body) && !is_numeric($body)) { |
75
|
1 |
|
throw new ClientException( |
76
|
1 |
|
'Body must be a string or int', |
77
|
|
|
\ALIBABA_CLOUD_INVALID_ARGUMENT |
78
|
1 |
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
6 |
|
if ($body === '') { |
82
|
1 |
|
throw new ClientException( |
83
|
1 |
|
'Body cannot be empty', |
84
|
|
|
\ALIBABA_CLOUD_INVALID_ARGUMENT |
85
|
1 |
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
5 |
|
return $body; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param $method |
93
|
|
|
* |
94
|
|
|
* @return mixed |
95
|
|
|
* @throws ClientException |
96
|
|
|
*/ |
97
|
73 |
|
public static function method($method) |
98
|
|
|
{ |
99
|
73 |
|
if (!is_string($method)) { |
100
|
1 |
|
throw new ClientException( |
101
|
1 |
|
'Method must be a string', |
102
|
|
|
\ALIBABA_CLOUD_INVALID_ARGUMENT |
103
|
1 |
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
72 |
|
if ($method === '') { |
107
|
1 |
|
throw new ClientException( |
108
|
1 |
|
'Method cannot be empty', |
109
|
|
|
\ALIBABA_CLOUD_INVALID_ARGUMENT |
110
|
1 |
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
71 |
|
return \strtoupper($method); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|