Browse Source

Update method to properly create our ServerRequest instance.

ADmad 7 years ago
parent
commit
79755c9978
1 changed files with 25 additions and 9 deletions
  1. 25 9
      src/Http/ServerRequestFactory.php

+ 25 - 9
src/Http/ServerRequestFactory.php

@@ -81,18 +81,34 @@ abstract class ServerRequestFactory implements ServerRequestFactoryInterface
     }
 
     /**
-     * {@inheritDoc}
+     * Create a new server request.
+     *
+     * Note that server-params are taken precisely as given - no parsing/processing
+     * of the given values is performed, and, in particular, no attempt is made to
+     * determine the HTTP method or URI, which must be provided explicitly.
+     *
+     * @param string $method The HTTP method associated with the request.
+     * @param \Psr\Http\Message\UriInterface|string $uri The URI associated with the request. If
+     *     the value is a string, the factory MUST create a UriInterface
+     *     instance based on it.
+     * @param array $serverParams Array of SAPI parameters with which to seed
+     *     the generated request instance.
+     *
+     * @return \Psr\Http\Message\ServerRequestInterface
      */
     public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
     {
-        $uploadedFiles = [];
-
-        return new ServerRequest(
-            $serverParams,
-            $uploadedFiles,
-            $uri,
-            $method
-        );
+        $options = ['environment' => $serverParams];
+
+        if ($uri instanceof UriInterface) {
+            $options['uri'] = $uri;
+        } else {
+            $options['url'] = $uri;
+        }
+
+        $request = new ServerRequest($options);
+
+        return $request->withMethod($method);
     }
 
     /**