Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 public function testWithUploadedFilesSetFilesToNewInstance()
 {
     $request = new ServerRequest();
     $files = ['foo' => ['name' => ['bar' => ['baz' => 'cor']], 'type' => ['bar' => ['baz' => 'con']], 'tmp_name' => ['bar' => ['baz' => 'cot']], 'error' => ['bar' => ['baz' => 0]], 'size' => ['bar' => ['baz' => 100]]]];
     $uploadedFiles = UploadedFilesFactory::make($files);
     $instance = $uploadedFiles['foo']['bar']['baz'];
     $new = $request->withUploadedFiles($uploadedFiles);
     $result = $new->getUploadedFiles();
     $this->assertTrue(isset($result['foo']['bar']['baz']));
     $this->assertSame($instance, $result['foo']['bar']['baz']);
 }
 public function testMakeMakesWithFlattenArrays()
 {
     $files = ['foo' => ['name' => ['foo', 'bar'], 'type' => ['bat', 'baz'], 'tmp_name' => ['con', 'com'], 'error' => [0, 0], 'size' => [100, 200]]];
     $result = UploadedFilesFactory::make($files);
     $this->assertTrue(is_array($result));
     $this->assertTrue(isset($result['foo']));
     $this->assertTrue(is_array($result['foo']));
     $this->assertSame(2, count($result['foo']));
     $first = $result['foo'][0];
     $this->assertInstanceOf(UploadedFile::CLASS, $first);
     $this->assertSame('foo', $first->getClientFileName());
     $this->assertSame('bat', $first->getClientMediaType());
     $this->assertSame('con', $first->getTempName());
     $this->assertSame(0, $first->getError());
     $this->assertSame(100, $first->getSize());
     $second = $result['foo'][1];
     $this->assertInstanceOf(UploadedFile::CLASS, $second);
     $this->assertSame('bar', $second->getClientFileName());
     $this->assertSame('baz', $second->getClientMediaType());
     $this->assertSame('com', $second->getTempName());
     $this->assertSame(0, $second->getError());
     $this->assertSame(200, $second->getSize());
 }
 public function testMakeCreateUploadedFilesFromFiles()
 {
     $_FILES = ['foo' => ['name' => 'bar', 'type' => 'bat', 'tmp_name' => 'baz', 'error' => 0, 'size' => 100]];
     $request = ServerRequestFactory::make();
     $this->assertEquals($request->getUploadedFiles(), UploadedFilesFactory::make());
 }