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

Commit af0b204

Browse files
committed
Merge branch 'feature/expose-server-factory-methods-as-functions' into develop
Close #307
2 parents 26efe24 + c5b2634 commit af0b204

14 files changed

+724
-400
lines changed

CHANGELOG.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,65 @@ All notable changes to this project will be documented in this file, in reverse
66

77
### Added
88

9-
- Nothing.
9+
- [#307](https://github.com/zendframework/zend-diactoros/pull/307) adds the following functions under the `Zend\Diactoros` namespace, each of
10+
which may be used to derive artifacts from SAPI supergloabls for the purposes
11+
of generating a `ServerRequest` instance:
12+
- `normalizeServer(array $server, callable $apacheRequestHeaderCallback = null) : array`
13+
(main purpose is to aggregate the `Authorization` header in the SAPI params
14+
when under Apache)
15+
- `marshalProtocolVersionFromSapi(array $server) : string`
16+
- `marshalMethodFromSapi(array $server) : string`
17+
- `marshalUriFromSapi(array $server, array $headers) : Uri`
18+
- `marshalHeadersFromSapi(array $server) : array`
19+
- `parseCookieHeader(string $header) : array`
20+
- `createUploadedFile(array $spec) : UploadedFile` (creates the instance from
21+
a normal `$_FILES` entry)
22+
- `normalizeUploadedFiles(array $files) : UploadedFileInterface[]` (traverses
23+
a potentially nested array of uploaded file instances and/or `$_FILES`
24+
entries, including those aggregated under mod_php, php-fpm, and php-cgi in
25+
order to create a flat array of `UploadedFileInterface` instances to use in a
26+
request)
1027

1128
### Changed
1229

1330
- Nothing.
1431

1532
### Deprecated
1633

34+
- [#307](https://github.com/zendframework/zend-diactoros/pull/307) deprecates `ServerRequestFactory::normalizeServer()`; the method is
35+
no longer used internally, and users should instead use `Zend\Diactoros\normalizeServer()`,
36+
to which it proxies.
37+
38+
- [#307](https://github.com/zendframework/zend-diactoros/pull/307) deprecates `ServerRequestFactory::marshalHeaders()`; the method is
39+
no longer used internally, and users should instead use `Zend\Diactoros\marshalHeadersFromSapi()`,
40+
to which it proxies.
41+
42+
- [#307](https://github.com/zendframework/zend-diactoros/pull/307) deprecates `ServerRequestFactory::marshalUriFromServer()`; the method
43+
is no longer used internally. Users should use `marshalUriFromSapi()` instead.
44+
45+
- [#307](https://github.com/zendframework/zend-diactoros/pull/307) deprecates `ServerRequestFactory::marshalRequestUri()`. the method is no longer
46+
used internally, and currently proxies to `marshalUriFromSapi()`, pulling the
47+
discovered path from the `Uri` instance returned by that function. Users
48+
should use `marshalUriFromSapi()` instead.
49+
50+
- [#307](https://github.com/zendframework/zend-diactoros/pull/307) deprecates `ServerRequestFactory::marshalHostAndPortFromHeaders()`; the method
51+
is no longer used internally, and currently proxies to `marshalUriFromSapi()`,
52+
pulling the discovered host and port from the `Uri` instance returned by that
53+
function. Users should use `marshalUriFromSapi()` instead.
54+
55+
- [#307](https://github.com/zendframework/zend-diactoros/pull/307) deprecates `ServerRequestFactory::getHeader()`; the method is no longer
56+
used internally. Users should copy and paste the functionality into their own
57+
applications if needed, or rely on headers from a fully-populated `Uri`
58+
instance instead.
59+
60+
- [#307](https://github.com/zendframework/zend-diactoros/pull/307) deprecates `ServerRequestFactory::stripQueryString()`; the method is no longer
61+
used internally, and users can mimic the functionality via the expression
62+
`$path = explode('?', $path, 2)[0];`.
63+
64+
- [#307](https://github.com/zendframework/zend-diactoros/pull/307) deprecates `ServerRequestFactory::normalizeFiles()`; the functionality
65+
is no longer used internally, and users can use `normalizeUploadedFiles()` as
66+
a replacement.
67+
1768
- [#303](https://github.com/zendframework/zend-diactoros/pull/303) deprecates `Zend\Diactoros\Response\EmitterInterface` and its various implementations. These are now provided via the
1869
[zendframework/zend-httphandlerrunner](https://docs.zendframework.com/zend-httphandlerrunner) package as 1:1 substitutions.
1970

composer.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
"psr/http-message-implementation": "1.0"
3838
},
3939
"autoload": {
40+
"files": [
41+
"src/functions/create_uploaded_file.php",
42+
"src/functions/marshal_headers_from_sapi.php",
43+
"src/functions/marshal_method_from_sapi.php",
44+
"src/functions/marshal_protocol_version_from_sapi.php",
45+
"src/functions/marshal_uri_from_sapi.php",
46+
"src/functions/normalize_server.php",
47+
"src/functions/normalize_uploaded_files.php",
48+
"src/functions/parse_cookie_header.php"
49+
],
4050
"psr-4": {
4151
"Zend\\Diactoros\\": "src/"
4252
}

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/book/api.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,31 @@ $request = RequestFactory::fromGlobals(
128128
);
129129
```
130130

131+
### ServerRequestFactory helper functions
132+
133+
- Since 1.8.0
134+
135+
In order to create the various artifacts required by a `ServerRequest` instance,
136+
Diactoros also provides a number of functions under the `Zend\Diactoros`
137+
namespace for introspecting the SAPI `$_SERVER` parameters, headers, `$_FILES`,
138+
and even the `Cookie` header. These include:
139+
140+
- `Zend\Diactoros\normalizeServer(array $server, callable $apacheRequestHeaderCallback = null) : array`
141+
(its main purpose is to aggregate the `Authorization` header in the SAPI params
142+
when under Apache)
143+
- `Zend\Diactoros\marshalProtocolVersionFromSapi(array $server) : string`
144+
- `Zend\Diactoros\marshalMethodFromSapi(array $server) : string`
145+
- `Zend\Diactoros\marshalUriFromSapi(array $server, array $headers) : Uri`
146+
- `Zend\Diactoros\marshalHeadersFromSapi(array $server) : array`
147+
- `Zend\Diactoros\parseCookieHeader(string $header) : array`
148+
- `Zend\Diactoros\createUploadedFile(array $spec) : UploadedFile` (creates the
149+
instance from a normal `$_FILES` entry)
150+
- `Zend\Diactoros\normalizeUploadedFiles(array $files) : UploadedFileInterface[]`
151+
(traverses a potentially nested array of uploaded file instances and/or
152+
`$_FILES` entries, including those aggregated under mod_php, php-fpm, and
153+
php-cgi in order to create a flat array of `UploadedFileInterface` instances
154+
to use in a request)
155+
131156
## URI
132157

133158
`Zend\Diactoros\Uri` is an implementation of

0 commit comments

Comments
 (0)