Skip to content

Commit c47ecf5

Browse files
committed
🚿
1 parent 5555409 commit c47ecf5

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

src/Psr7/MultipartStream.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ final class MultipartStream extends StreamAbstract{
4141
* MultipartStream constructor.
4242
*
4343
* @param array $elements [
44-
* name => string,
44+
* name => string,
4545
* contents => StreamInterface/resource/string,
46-
* headers => array,
46+
* headers => array,
4747
* filename => string
4848
* ]
4949
* @param string|null $boundary
@@ -148,9 +148,15 @@ public function addElement(array $e):MultipartStream{
148148
return $this;
149149
}
150150

151-
151+
/**
152+
* @param array $headers
153+
* @param $key
154+
*
155+
* @return bool
156+
*/
152157
private function hasHeader(array $headers, $key){
153158
$lowercaseHeader = strtolower($key);
159+
154160
foreach ($headers as $k => $v) {
155161
if (strtolower($k) === $lowercaseHeader) {
156162
return true;

src/Psr7/message_helpers.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ function normalize_request_headers(array $headers):array{
162162
}
163163

164164
/**
165-
* @param mixed $data
165+
* @param string|array $data
166166
*
167-
* @return mixed
167+
* @return string|array
168168
*/
169-
function raw_urlencode($data){
169+
function r_rawurlencode($data){
170170

171171
if(is_array($data)){
172-
return array_map(__NAMESPACE__.'\\raw_urlencode', $data);
172+
return array_map(__NAMESPACE__.'\\r_rawurlencode', $data);
173173
}
174174

175175
return rawurlencode($data);
@@ -194,8 +194,8 @@ function build_http_query(array $params, bool $urlencode = null, string $delimit
194194
// urlencode both keys and values
195195
if($urlencode ?? true){
196196
$params = array_combine(
197-
raw_urlencode(array_keys($params)),
198-
raw_urlencode(array_values($params))
197+
r_rawurlencode(array_keys($params)),
198+
r_rawurlencode(array_values($params))
199199
);
200200
}
201201

@@ -246,7 +246,7 @@ function build_http_query(array $params, bool $urlencode = null, string $delimit
246246
*
247247
* @return array
248248
*/
249-
function clean_query_params(iterable $params, int $bool_cast = null, bool $remove_empty = null):array{
249+
function clean_query_params(iterable $params, int $bool_cast = null, bool $remove_empty = null):iterable{
250250
$p = [];
251251
$bool_cast = $bool_cast ?? BOOLEANS_AS_BOOL;
252252
$remove_empty = $remove_empty ?? true;
@@ -269,6 +269,9 @@ function clean_query_params(iterable $params, int $bool_cast = null, bool $remov
269269
}
270270

271271
}
272+
elseif(is_iterable($value)){
273+
$p[$key] = call_user_func_array(__NAMESPACE__.'\\clean_query_params', [$value, $bool_cast, $remove_empty]);
274+
}
272275
elseif($remove_empty === true && ($value === null || (!is_numeric($value) && empty($value)))){
273276
continue;
274277
}
@@ -410,7 +413,7 @@ function get_xml(ResponseInterface $response){
410413
*
411414
* @return string
412415
*/
413-
function message_to_string(MessageInterface $message){
416+
function message_to_string(MessageInterface $message):string{
414417

415418
if($message instanceof RequestInterface){
416419
$msg = trim($message->getMethod().' '.$message->getRequestTarget()).' HTTP/'.$message->getProtocolVersion();
@@ -423,13 +426,10 @@ function message_to_string(MessageInterface $message){
423426
elseif($message instanceof ResponseInterface){
424427
$msg = 'HTTP/'.$message->getProtocolVersion().' '.$message->getStatusCode().' '.$message->getReasonPhrase();
425428
}
426-
else{
427-
throw new \InvalidArgumentException('Unknown message type');
428-
}
429429

430430
foreach($message->getHeaders() as $name => $values){
431-
$msg .= "\r\n{$name}: ".implode(', ', $values);
431+
$msg .= "\r\n".$name.': '.implode(', ', $values);
432432
}
433433

434-
return "{$msg}\r\n\r\n".$message->getBody();
434+
return $msg."\r\n\r\n".$message->getBody();
435435
}

0 commit comments

Comments
 (0)