Esempio n. 1
0
 public function testCreatesMultipartUploadWithMultiFields()
 {
     $b = new PostBody();
     $b->setField('testing', ['baz', 'bar']);
     $b->setField('other', 'hi');
     $b->setField('third', 'there');
     $b->addFile(new PostFile('foo', fopen(__FILE__, 'r')));
     $s = (string) $b;
     $this->assertContains(file_get_contents(__FILE__), $s);
     $this->assertContains('testing=bar', $s);
     $this->assertContains('Content-Disposition: form-data; name="third"', $s);
     $this->assertContains('Content-Disposition: form-data; name="other"', $s);
 }
 /**
  * Apply POST fields and files to a request to attempt to give an accurate
  * representation.
  *
  * @param RequestInterface $request Request to update
  * @param array            $body    Body to apply
  */
 protected function addPostData(RequestInterface $request, array $body)
 {
     static $fields = ['string' => true, 'array' => true, 'NULL' => true, 'boolean' => true, 'double' => true, 'integer' => true];
     $post = new PostBody();
     foreach ($body as $key => $value) {
         if (isset($fields[gettype($value)])) {
             $post->setField($key, $value);
         } elseif ($value instanceof PostFileInterface) {
             $post->addFile($value);
         } else {
             $post->addFile(new PostFile($key, $value));
         }
     }
     if ($request->getHeader('Content-Type') == 'multipart/form-data') {
         $post->forceMultipartUpload(true);
     }
     $request->setBody($post);
 }