/** * 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; }
/** * 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; }
public function testCanDetermineSizeFromMultipleStreams() { $a = new AppendStream([Stream::factory('foo'), Stream::factory('bar')]); $this->assertEquals(6, $a->getSize()); $s = $this->getMockBuilder('GuzzleHttp\\Stream\\StreamInterface')->setMethods(['isSeekable', 'isReadable'])->getMockForAbstractClass(); $s->expects($this->once())->method('isSeekable')->will($this->returnValue(null)); $s->expects($this->once())->method('isReadable')->will($this->returnValue(true)); $a->addStream($s); $this->assertNull($a->getSize()); }