1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright (c) 2016, 2017 François Kooman <[email protected]>. |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in all |
14
|
|
|
* copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22
|
|
|
* SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace fkooman\OAuth\Client\Http; |
26
|
|
|
|
27
|
|
|
class Request |
28
|
|
|
{ |
29
|
|
|
/** @var string */ |
30
|
|
|
private $requestMethod; |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
private $requestUri; |
34
|
|
|
|
35
|
|
|
/** @var string|null */ |
36
|
|
|
private $requestBody; |
37
|
|
|
|
38
|
|
|
/** @var array */ |
39
|
|
|
private $requestHeaders; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $requestMethod |
43
|
|
|
* @param string $requestUri |
44
|
|
|
* @param array $requestHeaders |
45
|
|
|
* @param string $requestBody |
46
|
|
|
*/ |
47
|
|
|
public function __construct($requestMethod, $requestUri, array $requestHeaders = [], $requestBody = null) |
48
|
|
|
{ |
49
|
|
|
$this->requestMethod = $requestMethod; |
50
|
|
|
$this->requestUri = $requestUri; |
51
|
|
|
$this->requestBody = $requestBody; |
52
|
|
|
$this->requestHeaders = $requestHeaders; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $requestUri |
57
|
|
|
* @param array $requestHeaders |
58
|
|
|
*/ |
59
|
|
|
public static function get($requestUri, array $requestHeaders = []) |
60
|
|
|
{ |
61
|
|
|
return new self('GET', $requestUri, $requestHeaders); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $requestUri |
66
|
|
|
* @param array $postData |
67
|
|
|
* @param array $requestHeaders |
68
|
|
|
*/ |
69
|
|
|
public static function post($requestUri, array $postData = [], array $requestHeaders = []) |
70
|
|
|
{ |
71
|
|
|
return new self( |
72
|
|
|
'POST', |
73
|
|
|
$requestUri, |
74
|
|
|
array_merge( |
75
|
|
|
$requestHeaders, |
76
|
|
|
['Content-Type' => 'application/x-www-form-urlencoded'] |
77
|
|
|
), |
78
|
|
|
http_build_query($postData, '&') |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $key |
84
|
|
|
* @param string $value |
85
|
|
|
*/ |
86
|
|
|
public function setHeader($key, $value) |
87
|
|
|
{ |
88
|
|
|
$this->requestHeaders[$key] = $value; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
|
|
public function getMethod() |
95
|
|
|
{ |
96
|
|
|
return $this->requestMethod; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getUri() |
103
|
|
|
{ |
104
|
|
|
return $this->requestUri; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return string|null |
109
|
|
|
*/ |
110
|
|
|
public function getBody() |
111
|
|
|
{ |
112
|
|
|
return $this->requestBody; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
|
|
public function getHeaders() |
119
|
|
|
{ |
120
|
|
|
return $this->requestHeaders; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|