1 | <?php |
||
15 | class ServerRequestCreator |
||
16 | { |
||
17 | private $serverRequestFactory; |
||
18 | |||
19 | private $uriFactory; |
||
20 | |||
21 | private $uploadedFileFactory; |
||
22 | |||
23 | private $streamFactory; |
||
24 | |||
25 | 14 | public function __construct( |
|
36 | |||
37 | /** |
||
38 | * Create a new server request from the current environment variables. |
||
39 | * Defaults to a GET request to minimise the risk of an \InvalidArgumentException. |
||
40 | * Includes the current request headers as supplied by the server through `getallheaders()`. |
||
41 | * |
||
42 | * @throws \InvalidArgumentException If no valid method or URI can be determined. |
||
43 | */ |
||
44 | public function fromGlobals(): ServerRequestInterface |
||
54 | |||
55 | /** |
||
56 | * Create a new server request from a set of arrays. |
||
57 | * |
||
58 | * @param array $server Typically $_SERVER or similar structure. |
||
59 | * @param array $headers Typically the output of getallheaders() or similar structure. |
||
60 | * @param array $cookie Typically $_COOKIE or similar structure. |
||
61 | * @param array $get Typically $_GET or similar structure. |
||
62 | * @param array $post Typically $_POST or similar structure. |
||
63 | * @param array $files Typically $_FILES or similar structure. |
||
64 | * |
||
65 | * @throws \InvalidArgumentException If no valid method or URI can be determined. |
||
66 | */ |
||
67 | public function fromArrays(array $server, array $headers = [], array $cookie = [], array $get = [], array $post = [], array $files = []): ServerRequestInterface |
||
85 | |||
86 | private function getMethodFromEnv(array $environment): string |
||
94 | |||
95 | private function getUriFromEnvWithHTTP(array $environment): UriInterface |
||
104 | |||
105 | /** |
||
106 | * Return an UploadedFile instance array. |
||
107 | * |
||
108 | * @param array $files A array which respect $_FILES structure |
||
109 | * |
||
110 | * @throws \InvalidArgumentException for unrecognized values |
||
111 | */ |
||
112 | private function normalizeFiles(array $files): array |
||
130 | |||
131 | /** |
||
132 | * Create and return an UploadedFile instance from a $_FILES specification. |
||
133 | * |
||
134 | * If the specification represents an array of values, this method will |
||
135 | * delegate to normalizeNestedFileSpec() and return that return value. |
||
136 | * |
||
137 | * @param array $value $_FILES struct |
||
138 | * |
||
139 | * @return array|UploadedFileInterface |
||
140 | */ |
||
141 | private function createUploadedFileFromSpec(array $value) |
||
155 | |||
156 | /** |
||
157 | * Normalize an array of file specifications. |
||
158 | * |
||
159 | * Loops through all nested files and returns a normalized array of |
||
160 | * UploadedFileInterface instances. |
||
161 | * |
||
162 | * @param array $files |
||
163 | * |
||
164 | * @return UploadedFileInterface[] |
||
165 | */ |
||
166 | private function normalizeNestedFileSpec(array $files = []): array |
||
183 | |||
184 | /** |
||
185 | * Create a new uri from server variable. |
||
186 | * |
||
187 | * @param array $server Typically $_SERVER or similar structure. |
||
188 | */ |
||
189 | 6 | private function createUriFromArray(array $server): UriInterface |
|
219 | } |
||
220 |