/**
     * Create the aggregate stream that will be used to upload the POST data
     */
    private function createStream(array $fields, array $files)
    {
        $stream = new Stream\AppendStream();

        foreach ($fields as $name => $field) {
            $stream->addStream(
                Stream\create($this->getFieldString($name, $field))
            );
        }

        foreach ($files as $file) {

            if (!$file instanceof PostFileInterface) {
                throw new \InvalidArgumentException('All POST fields must '
                    . 'implement PostFieldInterface');
            }

            $stream->addStream(
                Stream\create($this->getFileHeaders($file))
            );
            $stream->addStream($file->getContent());
            $stream->addStream(Stream\create("\r\n"));
        }

        // Add the trailing boundary
        $stream->addStream(Stream\create("--{$this->boundary}--"));

        return $stream;
    }
Exemple #2
0
 /**
  * Create the aggregate stream that will be used to upload the POST data
  */
 protected function createStream(array $fields, array $files)
 {
     $stream = new AppendStream();
     foreach ($fields as $name => $fieldValues) {
         foreach ((array) $fieldValues as $value) {
             $stream->addStream(Stream::factory($this->getFieldString($name, $value)));
         }
     }
     foreach ($files as $file) {
         if (!$file instanceof PostFileInterface) {
             throw new \InvalidArgumentException('All POST fields must ' . 'implement PostFieldInterface');
         }
         $stream->addStream(Stream::factory($this->getFileHeaders($file)));
         $stream->addStream($file->getContent());
         $stream->addStream(Stream::factory("\r\n"));
     }
     // Add the trailing boundary with CRLF
     $stream->addStream(Stream::factory("--{$this->boundary}--\r\n"));
     return $stream;
 }
Exemple #3
0
 /**
  * @expectedException \GuzzleHttp\Stream\Exception\CannotAttachException
  */
 public function testCannotAttach()
 {
     $p = new AppendStream();
     $p->attach('a');
 }
Exemple #4
0
 public function testFlushReturnsFalse()
 {
     $s = new AppendStream();
     $this->assertFalse($s->flush());
 }
 public function testCatchesExceptionsWhenCastingToString()
 {
     $s = $this->getMockBuilder('GuzzleHttp\\Stream\\StreamInterface')->setMethods(['read', 'isReadable', 'eof'])->getMockForAbstractClass();
     $s->expects($this->once())->method('read')->will($this->throwException(new \RuntimeException('foo')));
     $s->expects($this->once())->method('isReadable')->will($this->returnValue(true));
     $s->expects($this->any())->method('eof')->will($this->returnValue(false));
     $a = new AppendStream([$s]);
     $this->assertFalse($a->eof());
     $this->assertSame('', (string) $a);
 }