diff --git a/composer.json b/composer.json index 4bb275e..5baa4af 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.1-dev" + "dev-master": "1.x-dev" } } } diff --git a/src/MultipartStreamBuilder.php b/src/MultipartStreamBuilder.php index 7eeb876..f74c365 100644 --- a/src/MultipartStreamBuilder.php +++ b/src/MultipartStreamBuilder.php @@ -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 = []; @@ -72,6 +72,24 @@ 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. * @@ -104,9 +122,8 @@ 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']]; - return $this; + return $this->addData($stream, $options['headers']); } /**