Ejemplo n.º 1
0
 /**
  * @param array $server
  * @param array $get
  * @param array $post
  * @param array $cookies
  * @param array $files
  * @param \Psr\Http\Message\StreamInterface $stream
  * @return \Psr\Http\Message\ServerRequestInterface
  */
 public function create(array $server, array $get, array $post, array $cookies, array $files, StreamInterface $stream = null)
 {
     if (!isset($stream)) {
         $stream = new Stream('php://memory');
     }
     $headers = $this->getPsrHeadersFromServerParams($server);
     // exists body, but not exists posts
     $bodyContent = $stream->__toString();
     if ($bodyContent !== '' && count($post) === 0) {
         if (isset($headers['content-type'])) {
             // do not define multipart/form-data
             // because, it use only in POST method.
             // ref. en: https://issues.apache.org/jira/browse/FILEUPLOAD-197#comment-13595136
             // ref. kr: https://blog.outsider.ne.kr/1001
             if (strpos($headers['content-type'], 'application/json') === 0) {
                 $jsonBody = json_decode($bodyContent, true);
                 $post = $jsonBody ? $jsonBody : $post;
             } elseif (strpos($headers['content-type'], 'application/x-www-form-urlencoded') === 0) {
                 parse_str($bodyContent, $post);
             }
         }
     }
     return new ServerRequest($server, $get, $post, $cookies, $this->fileFactory->createFromFiles($files), [], isset($server['REQUEST_METHOD']) ? $server['REQUEST_METHOD'] : 'GET', $this->getUri($server), $stream, $headers, '1.1');
 }
Ejemplo n.º 2
0
 public function testMultiDepth()
 {
     $this->assertEquals(['main' => ['sub1' => [new UploadedFile('/private/var/abcdefg', 6171, 0, 'sub1_0.png', 'image/png'), new UploadedFile('/private/var/abcdefg', 6172, 0, 'sub1_1.png', 'image/png')], 'sub2' => ['sub1' => new UploadedFile('/private/var/abcdefg', 6173, 0, 'sub2_sub1.png', 'image/png'), 'sub2' => new UploadedFile('/private/var/abcdefg', 6174, 0, 'sub2_sub2.png', 'image/png')]]], $this->factory->createFromFiles(['main' => ['name' => ['sub1' => ['sub1_0.png', 'sub1_1.png'], 'sub2' => ['sub1' => 'sub2_sub1.png', 'sub2' => 'sub2_sub2.png']], 'type' => ['sub1' => ['image/png', 'image/png'], 'sub2' => ['sub1' => 'image/png', 'sub2' => 'image/png']], 'tmp_name' => ['sub1' => ['/private/var/abcdefg', '/private/var/abcdefg'], 'sub2' => ['sub1' => '/private/var/abcdefg', 'sub2' => '/private/var/abcdefg']], 'error' => ['sub1' => [0, 0], 'sub2' => ['sub1' => 0, 'sub2' => 0]], 'size' => ['sub1' => [6171, 6172], 'sub2' => ['sub1' => 6173, 'sub2' => 6174]]]]));
 }
Ejemplo n.º 3
0
 /**
  * @param array $server
  * @param array $get
  * @param array $post
  * @param array $cookies
  * @param array $files
  * @return ServerRequestInterface
  */
 public static function create(array $server, array $get, array $post, array $cookies, array $files)
 {
     return new ServerRequest($server, $cookies, $get, UploadedFileFactory::fromFiles($files), $post, [], '1.1', static::getUri($server));
 }