Exemplo n.º 1
0
 public function testMakeCreateStreamWithDataOfSource()
 {
     $content = 'Lorem ipsum dolor sit amet';
     $source = fopen('php://temp', 'w+b');
     fwrite($source, $content);
     InputFactory::setSource($source);
     $stream = InputFactory::make();
     $this->assertInstanceOf('Psr\\Http\\Message\\StreamInterface', $stream);
     $this->assertSame($content, $stream->getContents());
 }
Exemplo n.º 2
0
 /**
  * Makes the instance of Server Request.
  *
  * @param null|array $serverParams  Optional; the server parameters
  * @param null|array $cookieParams  Optional; the cookies, if any
  * @param null|array $queryParams   Optional; the query parameters, if any
  * @param null|array $uploadedFiles Optional; the uploaded files, if any
  * @param null|array $attributes    Optional; the application-specified attributes
  *
  * <!-- -->
  * @param null|array|object $parsedBody Optional; the parsed body
  *
  * <!-- -->
  * @param null|string|resource|\Psr\Http\Message\StreamInterface $body Optional; the body
  *
  * <!-- -->
  * @param null|array $headers Optional; the headers
  *
  * <!-- -->
  * @param null|string|\Psr\Http\Message\UriInterface $uri Optional; the URI
  *
  * <!-- -->
  * @param null|string $method   Optional; the request method
  * @param null|string $protocol Optional; the HTTP protocol version
  */
 public static function make(array $serverParams = null, array $cookieParams = null, array $queryParams = null, array $uploadedFiles = null, array $attributes = null, $parsedBody = null, $body = null, array $headers = null, $uri = null, $method = null, $protocol = null)
 {
     $cookies = $cookieParams ? $cookieParams : $_COOKIE;
     $server = $serverParams ? $serverParams : $_SERVER;
     $files = UploadedFilesFactory::make($uploadedFiles);
     $attributes = array_merge((array) $attributes, $_ENV);
     $query = $queryParams ? $queryParams : $_GET;
     $parsedBody = $parsedBody ? $parsedBody : $_POST;
     $body = $body ? $body : InputFactory::make();
     $uri = $uri ? $uri : UriFactory::make($server);
     $headers = $headers ? $headers : HeadersFactory::make($server);
     $method = $method ? $method : RequestMethodFactory::make($server);
     $protocol = $protocol ? $protocol : RequestProtocolFactory::getVersion($server);
     return new ServerRequest($server, $cookies, $query, $files, $attributes, $parsedBody, $body, $headers, $uri, $method, $protocol);
 }
 public function testMakeCreateInput()
 {
     $source = Stream::fopen();
     fwrite($source, 'Lorem ipsum dolor sit amet');
     InputFactory::setSource($source);
     $input = InputFactory::make();
     $request = ServerRequestFactory::make();
     $body = $request->getBody();
     $this->assertEquals($body->getContents(), $input->getContents());
     InputFactory::setSource(null);
 }