Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/MultipartStreamBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MultipartStreamBuilder
private $boundary;

/**
* @var array Element where each Element is an array with keys ['contents', 'headers', 'filename']
* @var array Element where each Element is an array with keys ['contents', 'headers']
*/
private $data = [];

Expand Down Expand Up @@ -72,6 +72,23 @@ public function __construct($streamFactory = null)
}
}

/**
* Add a resource to the Multipart Stream
*
* @param string|resource|\Psr\Http\Message\StreamInterface $resource
* The filepath, resource or StreamInterface of the data.
* @param array $headers
* Additional headers array: ['header-name' => 'header-value'].
*
* @return MultipartStreamBuilder
*/
public function addData($resource, array $headers = [])
{
$stream = $this->createStream($resource);
$this->data[] = ['contents' => $stream, 'headers' => $headers];
return $this;
}

/**
* Add a resource to the Multipart Stream.
*
Expand Down Expand Up @@ -104,8 +121,7 @@ public function addResource($name, $resource, array $options = [])
}

$this->prepareHeaders($name, $stream, $options['filename'], $options['headers']);
$this->data[] = ['contents' => $stream, 'headers' => $options['headers'], 'filename' => $options['filename']];

$this->addData($stream, $options['headers']);
return $this;
}

Expand Down