/** * Create the aggregate stream that will be used to upload the POST data */ private function createStream(array $fields, array $files) { $this->stream = new Stream\AppendStream(); foreach ($fields as $name => $field) { $this->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'); } $this->stream->addStream(Stream\create($this->getFileHeaders($file))); $this->stream->addStream($file->getContent()); $this->stream->addStream(Stream\create("\r\n")); } // Add the trailing boundary $this->stream->addStream(Stream\create("--{$this->boundary}--")); }