88 * @author Michael Dowling and contributors to guzzlehttp/psr7
99 * @author Tobias Nyholm <[email protected] > 1010 */
11- class MultipartStream implements StreamInterface
11+ class MultipartStream implements MultipartStreamInterface
1212{
1313 /**
1414 * @var StreamInterface[] Streams being decorated
@@ -41,7 +41,8 @@ class MultipartStream implements StreamInterface
4141 private $ boundary ;
4242
4343 /**
44- * @param StreamInterface[] $streams Streams to decorate. Each stream must be readable.
44+ * @param StreamInterface[] $streams Streams to decorate. Each stream must be readable. The streams should also
45+ * include the boundary.
4546 * @param string $boundary
4647 */
4748 public function __construct (array $ streams = [], $ boundary )
@@ -63,13 +64,13 @@ public function __toString()
6364 }
6465
6566 /**
66- * Add a stream to the AppendStream
67+ * Add a stream to the MultipartStream
6768 *
6869 * @param StreamInterface $stream Stream to append. Must be readable.
6970 *
7071 * @throws \InvalidArgumentException if the stream is not readable
7172 */
72- public function addStream (StreamInterface $ stream )
73+ private function addStream (StreamInterface $ stream )
7374 {
7475 if (!$ stream ->isReadable ()) {
7576 throw new \InvalidArgumentException ('Each stream must be readable ' );
@@ -83,9 +84,31 @@ public function addStream(StreamInterface $stream)
8384 $ this ->streams [] = $ stream ;
8485 }
8586
87+ /**
88+ * {@inheritdoc}
89+ */
90+ public function getBoundary ()
91+ {
92+ return $ this ->boundary ;
93+ }
94+
95+ /**
96+ * {@inheritdoc}
97+ */
8698 public function getContents ()
8799 {
88- return copy_to_string ($ this );
100+ $ buffer = '' ;
101+
102+ while (!$ this ->eof ()) {
103+ $ buf = $ this ->read (1048576 );
104+ // Using a loose equality here to match on '' and false.
105+ if ($ buf == null ) {
106+ break ;
107+ }
108+ $ buffer .= $ buf ;
109+ }
110+
111+ return $ buffer ;
89112 }
90113
91114 /**
0 commit comments