Skip to content

Commit 70473cf

Browse files
committed
🚿
1 parent 3490842 commit 70473cf

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

src/Query.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
namespace chillerlan\HTTP\Utils;
1212

13-
use function array_merge, explode, implode, is_array, is_bool, is_string, parse_url, rawurldecode, sort, str_replace, uksort;
14-
use const PHP_QUERY_RFC1738, PHP_QUERY_RFC3986, PHP_URL_QUERY, SORT_STRING;
13+
use function array_merge, explode, implode, is_array, is_bool, is_string, rawurldecode, sort, str_replace, uksort;
14+
use const PHP_QUERY_RFC1738, PHP_QUERY_RFC3986, SORT_STRING;
1515

1616
/**
1717
*
@@ -166,7 +166,7 @@ public static function build(array $params, int $encoding = null, string $delimi
166166
* @return string
167167
*/
168168
public static function merge(string $uri, array $query):string{
169-
$parsedquery = self::parse(parse_url($uri, PHP_URL_QUERY) ?: '');
169+
$parsedquery = self::parse(parseUrl($uri)['query'] ?? '');
170170
$requestURI = explode('?', $uri)[0];
171171
$params = array_merge($parsedquery, $query);
172172

src/Server.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,16 @@ public function createUriFromGlobals():UriInterface{
8282

8383
$uri = $this->uriFactory
8484
->createUri()
85-
->withScheme(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http');
85+
->withScheme(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http')
86+
;
8687

8788
if(isset($_SERVER['HTTP_HOST'])){
8889
$hostHeaderParts = explode(':', $_SERVER['HTTP_HOST']);
89-
$uri = $uri->withHost($hostHeaderParts[0]);
90+
$uri = $uri->withHost($hostHeaderParts[0]);
9091

9192
if(isset($hostHeaderParts[1])){
92-
$hasPort = true;
93-
$uri = $uri->withPort((int)$hostHeaderParts[1]);
93+
$hasPort = true;
94+
$uri = $uri->withPort((int)$hostHeaderParts[1]);
9495
}
9596
}
9697
elseif(isset($_SERVER['SERVER_NAME'])){
@@ -106,11 +107,11 @@ public function createUriFromGlobals():UriInterface{
106107

107108
if(isset($_SERVER['REQUEST_URI'])){
108109
$requestUriParts = explode('?', $_SERVER['REQUEST_URI']);
109-
$uri = $uri->withPath($requestUriParts[0]);
110+
$uri = $uri->withPath($requestUriParts[0]);
110111

111112
if(isset($requestUriParts[1])){
112-
$hasQuery = true;
113-
$uri = $uri->withQuery($requestUriParts[1]);
113+
$hasQuery = true;
114+
$uri = $uri->withQuery($requestUriParts[1]);
114115
}
115116
}
116117

@@ -207,5 +208,4 @@ public function normalizeNestedFileSpec(array $files):array{
207208
return $normalized;
208209
}
209210

210-
211211
}

src/message_helpers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function r_rawurlencode($data){
165165
* @return \stdClass|array|bool
166166
*/
167167
function get_json(MessageInterface $message, bool $assoc = null){
168-
$data = json_decode($message->getBody()->__toString(), $assoc);
168+
$data = json_decode((string)$message->getBody(), $assoc);
169169

170170
$message->getBody()->rewind();
171171

@@ -179,7 +179,7 @@ function get_json(MessageInterface $message, bool $assoc = null){
179179
* @return \SimpleXMLElement|array|bool
180180
*/
181181
function get_xml(MessageInterface $message, bool $assoc = null){
182-
$data = simplexml_load_string($message->getBody()->__toString());
182+
$data = simplexml_load_string((string)$message->getBody());
183183

184184
$message->getBody()->rewind();
185185

@@ -214,7 +214,7 @@ function message_to_string(MessageInterface $message):string{
214214
$msg .= "\r\n".$name.': '.implode(', ', $values);
215215
}
216216

217-
$data = $message->getBody()->__toString();
217+
$data = (string)$message->getBody();
218218
$message->getBody()->rewind();
219219

220220
return $msg."\r\n\r\n".$data;

tests/MessageHelpersTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ public function testRawurlencode($data, $expected):void{
4949
}
5050

5151
public function testRawurlencodeTypeErrorException():void{
52-
$this::expectException(TypeError::class);
52+
$this->expectException(TypeError::class);
5353

54-
/** @noinspection PhpParamsInspection */
55-
r_rawurlencode(new \stdClass());
54+
r_rawurlencode((object)[]);
5655
}
5756

5857
public function testGetJSON():void{

0 commit comments

Comments
 (0)