|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Ivory Http Adapter package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Ivory\HttpAdapter\Message; |
|
13
|
|
|
|
|
14
|
|
|
use Psr\Http\Message\StreamInterface; |
|
15
|
|
|
use Psr\Http\Message\UriInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @author GeLo <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class InternalRequest extends Request implements InternalRequestInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
private $datas = []; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
private $files = []; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param null|string|UriInterface $uri |
|
34
|
|
|
* @param null|string $method |
|
35
|
|
|
* @param string|resource|StreamInterface $body |
|
36
|
|
|
* @param array $datas |
|
37
|
|
|
* @param array $files |
|
38
|
|
|
* @param array $headers |
|
39
|
|
|
* @param array $parameters |
|
40
|
|
|
*/ |
|
41
|
15489 |
|
public function __construct( |
|
42
|
|
|
$uri = null, |
|
43
|
|
|
$method = null, |
|
44
|
|
|
$body = 'php://memory', |
|
45
|
|
|
array $datas = [], |
|
46
|
|
|
array $files = [], |
|
47
|
|
|
array $headers = [], |
|
48
|
|
|
array $parameters = [] |
|
49
|
|
|
) { |
|
50
|
15489 |
|
parent::__construct($uri, $method, $body, $headers, $parameters); |
|
51
|
|
|
|
|
52
|
15489 |
|
$this->datas = $datas; |
|
53
|
15489 |
|
$this->files = $files; |
|
54
|
15489 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
15426 |
|
public function getDatas() |
|
60
|
|
|
{ |
|
61
|
15426 |
|
return $this->datas; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
27 |
|
public function hasData($name) |
|
68
|
|
|
{ |
|
69
|
27 |
|
return isset($this->datas[$name]); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritdoc} |
|
74
|
|
|
*/ |
|
75
|
27 |
|
public function getData($name) |
|
76
|
|
|
{ |
|
77
|
27 |
|
return $this->hasData($name) ? $this->datas[$name] : null; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritdoc} |
|
82
|
|
|
*/ |
|
83
|
18 |
|
public function withData($name, $value) |
|
84
|
|
|
{ |
|
85
|
18 |
|
$new = clone $this; |
|
86
|
18 |
|
$new->datas[$name] = $value; |
|
87
|
|
|
|
|
88
|
18 |
|
return $new; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* {@inheritdoc} |
|
93
|
|
|
*/ |
|
94
|
9 |
|
public function withAddedData($name, $value) |
|
95
|
|
|
{ |
|
96
|
9 |
|
$new = clone $this; |
|
97
|
9 |
|
$new->datas[$name] = $new->hasData($name) |
|
98
|
9 |
|
? array_merge((array) $new->datas[$name], (array) $value) |
|
99
|
9 |
|
: $value; |
|
100
|
|
|
|
|
101
|
9 |
|
return $new; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* {@inheritdoc} |
|
106
|
|
|
*/ |
|
107
|
9 |
|
public function withoutData($name) |
|
108
|
|
|
{ |
|
109
|
9 |
|
$new = clone $this; |
|
110
|
9 |
|
unset($new->datas[$name]); |
|
111
|
|
|
|
|
112
|
9 |
|
return $new; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* {@inheritdoc} |
|
117
|
|
|
*/ |
|
118
|
15426 |
|
public function getFiles() |
|
119
|
|
|
{ |
|
120
|
15426 |
|
return $this->files; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* {@inheritdoc} |
|
125
|
|
|
*/ |
|
126
|
27 |
|
public function hasFile($name) |
|
127
|
|
|
{ |
|
128
|
27 |
|
return isset($this->files[$name]); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* {@inheritdoc} |
|
133
|
|
|
*/ |
|
134
|
27 |
|
public function getFile($name) |
|
135
|
|
|
{ |
|
136
|
27 |
|
return $this->hasFile($name) ? $this->files[$name] : null; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* {@inheritdoc} |
|
141
|
|
|
*/ |
|
142
|
18 |
|
public function withFile($name, $file) |
|
143
|
|
|
{ |
|
144
|
18 |
|
$new = clone $this; |
|
145
|
18 |
|
$new->files[$name] = $file; |
|
146
|
|
|
|
|
147
|
18 |
|
return $new; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* {@inheritdoc} |
|
152
|
|
|
*/ |
|
153
|
9 |
|
public function withAddedFile($name, $file) |
|
154
|
|
|
{ |
|
155
|
9 |
|
$new = clone $this; |
|
156
|
9 |
|
$new->files[$name] = $new->hasFile($name) |
|
157
|
9 |
|
? array_merge((array) $new->files[$name], (array) $file) |
|
158
|
9 |
|
: $file; |
|
159
|
|
|
|
|
160
|
9 |
|
return $new; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* {@inheritdoc} |
|
165
|
|
|
*/ |
|
166
|
9 |
|
public function withoutFile($name) |
|
167
|
|
|
{ |
|
168
|
9 |
|
$new = clone $this; |
|
169
|
9 |
|
unset($new->files[$name]); |
|
170
|
|
|
|
|
171
|
9 |
|
return $new; |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|