Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 4999a25

Browse files
committed
Consolidate functions for generating URI to a single exposed function
Moves `getHeaderFromArray()`, `marshalHostAndPort()`, and `marshalIpv6HostAndPort()` into `marshalUriFromSapi()` as anonymous functions, leaving only `marshalUriFromSapi()` exposed publicly; the others are simply implementation details of that particular function.
1 parent d94567a commit 4999a25

File tree

7 files changed

+206
-217
lines changed

7 files changed

+206
-217
lines changed

composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@
3939
"autoload": {
4040
"files": [
4141
"src/functions/create_uploaded_file.php",
42-
"src/functions/get_header_from_array.php",
4342
"src/functions/marshal_headers_from_sapi.php",
44-
"src/functions/marshal_host_and_port.php",
4543
"src/functions/marshal_protocol_version.php",
46-
"src/functions/marshal_request_path.php",
4744
"src/functions/marshal_uri_from_sapi.php",
4845
"src/functions/normalize_server.php",
4946
"src/functions/normalize_uploaded_files.php",

src/ServerRequestFactory.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,22 @@ public static function get($key, array $values, $default = null)
129129
*
130130
* If not, the $default is returned.
131131
*
132-
* @deprecated since 1.8.0; use Zend\Diactoros\getHeaderFromArray() instead.
132+
* @deprecated since 1.8.0; no longer used internally.
133133
* @param string $header
134134
* @param array $headers
135135
* @param mixed $default
136136
* @return string
137137
*/
138138
public static function getHeader($header, array $headers, $default = null)
139139
{
140-
return getHeaderFromArray($header, $headers, $default);
140+
$header = strtolower($name);
141+
$headers = array_change_key_case($headers, CASE_LOWER);
142+
if (array_key_exists($header, $headers)) {
143+
$value = is_array($headers[$header]) ? implode(', ', $headers[$header]) : $headers[$header];
144+
return $value;
145+
}
146+
147+
return $default;
141148
}
142149

143150
/**
@@ -201,16 +208,18 @@ public static function marshalUriFromServer(array $server, array $headers)
201208
/**
202209
* Marshal the host and port from HTTP headers and/or the PHP environment
203210
*
204-
* @deprecated since 1.8.0; use Zend\Diactoros\marshalHostAndPort instead.
211+
* @deprecated since 1.8.0; use Zend\Diactoros\marshalUriFromSapi() instead,
212+
* and pull the host and port from the Uri instance that function
213+
* returns.
205214
* @param stdClass $accumulator
206215
* @param array $server
207216
* @param array $headers
208217
*/
209218
public static function marshalHostAndPortFromHeaders(stdClass $accumulator, array $server, array $headers)
210219
{
211-
list($host, $port) = marshalHostAndPort($headers, $server);
212-
$accumulator->host = $host;
213-
$accumulator->port = $port;
220+
$uri = marshalUriFromSapi($server, $headers);
221+
$accumulator->host = $uri->getHost();
222+
$accumulator->port = $uri->getPort();
214223
}
215224

216225
/**
@@ -219,14 +228,15 @@ public static function marshalHostAndPortFromHeaders(stdClass $accumulator, arra
219228
* Looks at a variety of criteria in order to attempt to autodetect a base
220229
* URI, including rewrite URIs, proxy URIs, etc.
221230
*
222-
*
223-
* @deprecated since 1.8.0; use Zend\Diactoros\marshalRequestPath() instead.
231+
* @deprecated since 1.8.0; use Zend\Diactoros\marshalUriFromSapi() instead,
232+
* and pull the path from the Uri instance that function returns.
224233
* @param array $server
225234
* @return string
226235
*/
227236
public static function marshalRequestUri(array $server)
228237
{
229-
return marshalRequestPath($server);
238+
$uri = marshalUriFromSapi($server, []);
239+
return $uri->getPath();
230240
}
231241

232242
/**

src/functions/get_header_from_array.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/functions/marshal_host_and_port.php

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/functions/marshal_request_path.php

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)