From e45146608992bd09a0ab0f0d7206546f0e8274b9 Mon Sep 17 00:00:00 2001 From: Koala Yeung Date: Fri, 18 Dec 2020 17:57:17 +0800 Subject: [PATCH 1/4] Add MultipartStreamBuilder::addData * Added a public method addData for manipulating the private $data array properly. --- src/MultipartStreamBuilder.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/MultipartStreamBuilder.php b/src/MultipartStreamBuilder.php index 7eeb876..13fe09d 100644 --- a/src/MultipartStreamBuilder.php +++ b/src/MultipartStreamBuilder.php @@ -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. * From 7323e85dfe030b732499f0ec34e0530719319132 Mon Sep 17 00:00:00 2001 From: Koala Yeung Date: Tue, 22 Dec 2020 18:15:17 +0800 Subject: [PATCH 2/4] Rewrite MultipartStreamBuilder::addResource with addData * Rewrite with new addData method. * Remove internal 'filename' key from MultipartStreamBuilder::data. --- src/MultipartStreamBuilder.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/MultipartStreamBuilder.php b/src/MultipartStreamBuilder.php index 13fe09d..7632160 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 = []; @@ -121,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; } From 0db0d5c2688633415e6e2e35505863787a33cdde Mon Sep 17 00:00:00 2001 From: Koala Yeung Date: Tue, 22 Dec 2020 22:17:41 +0800 Subject: [PATCH 3/4] Update code formatting * add a line before final returns. * use addData to immediately return $this. --- src/MultipartStreamBuilder.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/MultipartStreamBuilder.php b/src/MultipartStreamBuilder.php index 7632160..f74c365 100644 --- a/src/MultipartStreamBuilder.php +++ b/src/MultipartStreamBuilder.php @@ -86,6 +86,7 @@ public function addData($resource, array $headers = []) { $stream = $this->createStream($resource); $this->data[] = ['contents' => $stream, 'headers' => $headers]; + return $this; } @@ -121,8 +122,8 @@ public function addResource($name, $resource, array $options = []) } $this->prepareHeaders($name, $stream, $options['filename'], $options['headers']); - $this->addData($stream, $options['headers']); - return $this; + + return $this->addData($stream, $options['headers']); } /** From 2ad833380bdafb7d2e16a41698dc3bc6a55428b9 Mon Sep 17 00:00:00 2001 From: Koala Yeung Date: Tue, 22 Dec 2020 22:42:38 +0800 Subject: [PATCH 4/4] composer.json: Change branch alias to 1.x-dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" } } }