Skip to content

Commit 5e02c79

Browse files
authored
Merge pull request #25 from php-http/issue-24
Allow us to reset the builder
2 parents cf58c6d + f3fd223 commit 5e02c79

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/MultipartStreamBuilder.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ public function setMimetypeHelper(MimetypeHelper $mimetypeHelper)
229229
return $this;
230230
}
231231

232+
/**
233+
* Reset and clear all stored data. This allows you to use builder for a subsequent request.
234+
*
235+
* @return MultipartStreamBuilder
236+
*/
237+
public function reset()
238+
{
239+
$this->data = [];
240+
$this->boundary = null;
241+
242+
return $this;
243+
}
244+
232245
/**
233246
* Gets the filename from a given path.
234247
*

tests/FunctionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ public function testBoundary()
103103
$this->assertEquals(5, substr_count($multipartStream, $boundary));
104104
}
105105

106+
public function testReset()
107+
{
108+
$boundary = 'SpecialBoundary';
109+
$builder = new MultipartStreamBuilder();
110+
$builder->addResource('content0', 'foobar');
111+
$builder->setBoundary($boundary);
112+
113+
$builder->reset();
114+
$multipartStream = (string) $builder->build();
115+
$this->assertNotContains('foobar', $multipartStream, 'Stream should not have any data after reset()');
116+
$this->assertNotEquals($boundary, $builder->getBoundary(), 'Stream should have a new boundary after reset()');
117+
$this->assertNotEmpty($builder->getBoundary());
118+
}
119+
106120
/**
107121
* @param string $body
108122
*

0 commit comments

Comments
 (0)