Skip to content

Commit ac1069d

Browse files
committed
Merge branch '2.x' into 1.x
* 2.x: use a single getDebugType method Utility\Uri::withParsedValues() convert null path to ''
2 parents 4661089 + ca844ba commit ac1069d

14 files changed

+61
-80
lines changed

.editorconfig

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,25 @@ https://EditorConfig.org/#download
44
root = true
55

66
[*]
7-
end_of_line = lf
87
charset = utf-8
8+
end_of_line = lf
9+
indent_style = space
10+
trim_trailing_whitespace = true
911

1012
[*.js]
1113
indent_size = 2
1214
insert_final_newline = true
13-
trim_trailing_whitespace = true
1415

1516
[*.json]
1617
indent_size = 2
1718
insert_final_newline = true
18-
trim_trailing_whitespace = true
1919

2020
[*.md]
2121
trim_trailing_whitespace = false
2222

2323
[*.php]
24-
indent_style = space
2524
indent_size = 4
2625
insert_final_newline = true
27-
trim_trailing_whitespace = true
2826

2927
[*.scss]
3028
indent_size = 2

src/HttpMessage/AbstractStream.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,6 @@ abstract class AbstractStream
3838
/** @var resource|closed-resource|null A resource reference */
3939
protected $resource;
4040

41-
/**
42-
* Gets the type name of a variable in a way that is suitable for debugging
43-
*
44-
* @param mixed $value The value being type checked
45-
*
46-
* @return string
47-
*/
48-
protected static function getDebugType($value)
49-
{
50-
return \is_object($value)
51-
? \get_class($value)
52-
: \strtolower(\gettype($value));
53-
}
54-
5541
/**
5642
* Safely test if value is a file
5743
*
@@ -112,7 +98,7 @@ protected function setResource($value)
11298
}
11399
throw new InvalidArgumentException(\sprintf(
114100
$this->strings['resourceInvalidType'],
115-
$this->getDebugType($value)
101+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($value)
116102
));
117103
}
118104

src/HttpMessage/AbstractUri.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected function assertPort($port)
9494
// for versions with int type-hint, this will never be reached
9595
throw new InvalidArgumentException(\sprintf(
9696
'Port must be a int, %s provided.',
97-
$this->getDebugType($port)
97+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($port)
9898
));
9999
}
100100
if ($port < 1 || $port > 0xffff) {

src/HttpMessage/AssertionTrait.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,10 @@ protected function assertString($value, $what = '', $allowNumeric = false, $allo
6565
throw new InvalidArgumentException(\sprintf(
6666
'%s must be a string, %s provided.',
6767
\ucfirst($what),
68-
$this->getDebugType($value)
68+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($value)
6969
));
7070
}
7171

72-
/**
73-
* Gets the type name of a variable in a way that is suitable for debugging
74-
*
75-
* @param mixed $value Value to inspect
76-
*
77-
* @return string
78-
*/
79-
protected static function getDebugType($value)
80-
{
81-
return \is_object($value)
82-
? \get_class($value)
83-
: \strtolower(\gettype($value));
84-
}
85-
8672
/*
8773
Message assertions
8874
*/
@@ -135,7 +121,7 @@ private function assertHeaderValue($value)
135121
if (\is_array($value) === false) {
136122
throw new InvalidArgumentException(\sprintf(
137123
'The header field value only accepts string and array, %s provided.',
138-
self::getDebugType($value)
124+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($value)
139125
));
140126
}
141127
if (empty($value)) {
@@ -212,7 +198,7 @@ private function assertProtocolVersion($version)
212198
if (\is_numeric($version) === false) {
213199
throw new InvalidArgumentException(\sprintf(
214200
'Unsupported HTTP protocol version number. %s provided.',
215-
self::getDebugType($version)
201+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($version)
216202
));
217203
}
218204
if (\in_array((string) $version, $this->validProtocolVers, true) === false) {
@@ -333,7 +319,7 @@ protected function assertQueryParams(array $get)
333319
throw new InvalidArgumentException(\sprintf(
334320
'Query params must only contain scalar values, %s contains %s.',
335321
$this->iteratorPath($iterator),
336-
$this->getDebugType($value)
322+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($value)
337323
));
338324
}
339325
}
@@ -359,7 +345,7 @@ protected function assertParsedBody($data)
359345
}
360346
throw new InvalidArgumentException(\sprintf(
361347
'ParsedBody must be array, object, or null. %s provided.',
362-
self::getDebugType($data)
348+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($data)
363349
));
364350
}
365351

@@ -378,7 +364,7 @@ protected function assertUploadedFiles(array $uploadedFiles)
378364
if (!($val instanceof UploadedFileInterface)) {
379365
throw new InvalidArgumentException(\sprintf(
380366
'Invalid file in uploaded files structure. Expected UploadedFileInterface, %s provided',
381-
self::getDebugType($val)
367+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($val)
382368
));
383369
}
384370
});
@@ -435,7 +421,7 @@ protected function assertStatusCode($code)
435421
if (\is_int($code) === false) {
436422
throw new InvalidArgumentException(\sprintf(
437423
'Status code must to be an integer, %s provided.',
438-
self::getDebugType($code)
424+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($code)
439425
));
440426
}
441427
if ($code < 100 || $code > 599) {

src/HttpMessage/ServerRequestExtended.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ public function getServerParam($key, $default = null)
183183
{
184184
$serverParams = $this->getServerParams();
185185
return isset($serverParams[$key])
186-
? $serverParams[$key]
187-
: $default;
186+
? $serverParams[$key]
187+
: $default;
188188
}
189189

190190
/**
@@ -195,7 +195,7 @@ public function isSecure()
195195
return $this->getServerParam('HTTPS') === 'on';
196196
}
197197

198-
/**
198+
/**
199199
* {@inheritDoc}
200200
*/
201201
public function isXhr()

src/HttpMessage/ServerRequestExtendedInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function getServerParam($key, $default = null);
170170
*/
171171
public function isSecure();
172172

173-
/**
173+
/**
174174
* Is this an XHR (aka ajax) request?
175175
*
176176
* Note: This method is not part of the PSR-7 standard.

src/HttpMessage/UploadedFile.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ private function assertSize($size)
395395
if ($size === null || (\is_int($size) && $size > -1)) {
396396
return;
397397
}
398-
throw new InvalidArgumentException(\sprintf('Upload file size must be a positive integer. %s provided', \gettype($size)));
398+
throw new InvalidArgumentException(\sprintf(
399+
'Upload file size must be a positive integer. %s provided',
400+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($size)
401+
));
399402
}
400403

401404
/**
@@ -418,7 +421,7 @@ private function assertStringOrNull($value, $key)
418421
throw new InvalidArgumentException(\sprintf(
419422
'Upload file %s must be a string or null. %s provided.',
420423
$key,
421-
\gettype($value)
424+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($value)
422425
));
423426
}
424427

src/HttpMessage/Utility/ParseStr.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ class ParseStr
5050
'convSpace' => false, // whether to convert ' ' to '_' (php's default is true)
5151
);
5252

53+
/**
54+
* Gets the type name of a variable in a way that is suitable for debugging
55+
*
56+
* @param mixed $value Value to inspect
57+
*
58+
* @return string
59+
*/
60+
public static function getDebugType($value)
61+
{
62+
if (\is_object($value)) {
63+
return \get_class($value);
64+
}
65+
return \strtr(\strtolower(\gettype($value)), array(
66+
'boolean' => 'bool',
67+
'double' => 'float',
68+
'integer' => 'int',
69+
));
70+
}
71+
5372
/**
5473
* like PHP's `parse_str()`
5574
*
@@ -107,20 +126,6 @@ public static function setOpts($mixed, $val = null)
107126
self::$parseStrOpts = \array_merge(self::$parseStrOpts, $mixed);
108127
}
109128

110-
/**
111-
* Gets the type name of a variable in a way that is suitable for debugging
112-
*
113-
* @param mixed $value Value to inspect
114-
*
115-
* @return string
116-
*/
117-
protected static function getDebugType($value)
118-
{
119-
return \is_object($value)
120-
? \get_class($value)
121-
: \strtolower(\gettype($value));
122-
}
123-
124129
/**
125130
* Parses request parameters from the specified string
126131
*

src/HttpMessage/Utility/ServerRequest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ private static function filesFromGlobals(array $phpFiles, array $path = [])
8484
foreach ($phpFiles as $key => $value) {
8585
$pathCurKey = $path;
8686
$pathCurKey[] = (string) $key;
87-
if (\is_array($value) === false) {
88-
throw new InvalidArgumentException(\sprintf(
89-
'Invalid value in files specification at %s. Array expected. %s provided.',
90-
\implode('.', $pathCurKey),
91-
\gettype($value)
92-
));
93-
}
94-
if (self::isUploadFileInfoArray($value)) {
95-
$files[$key] = self::fileFromGlobalCreate($value);
96-
continue;
97-
}
87+
if (\is_array($value) === false) {
88+
throw new InvalidArgumentException(\sprintf(
89+
'Invalid value in files specification at %s. Array expected. %s provided.',
90+
\implode('.', $pathCurKey),
91+
\bdk\HttpMessage\Utility\ParseStr::getDebugType($value)
92+
));
93+
}
94+
if (self::isUploadFileInfoArray($value)) {
95+
$files[$key] = self::fileFromGlobalCreate($value);
96+
continue;
97+
}
9898
$files[$key] = self::filesFromGlobals($value, $pathCurKey);
9999
}
100100
return $files;

src/HttpMessage/Utility/Uri.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,13 @@ public static function resolve(UriInterface $base, UriInterface $rel)
164164
*
165165
* @since x3.4
166166
*/
167-
public static function withParsedValues(UriInterface $uri, array $values): UriInterface
167+
public static function withParsedValues(UriInterface $uri, array $values)
168168
{
169169
$uriKeys = ['fragment', 'host', 'path', 'port', 'query', 'scheme', 'userInfo'];
170170
$values = \array_intersect_key(self::parsedPartsPrep($values), \array_flip($uriKeys));
171+
if (\array_key_exists('path', $values) && $values['path'] === null) {
172+
$values['path'] = '';
173+
}
171174
foreach ($values as $key => $value) {
172175
$method = 'with' . \ucfirst($key);
173176
// using call_user_func_array... some methods (withUserInfo) accept multiple arguments

0 commit comments

Comments
 (0)