-
Notifications
You must be signed in to change notification settings - Fork 11
Added support for multipart stream created from uri streams #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
9dffb33
edb3165
ec9a031
b303f78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,14 @@ public function build() | |
$this->getHeaders($data['headers'])."\r\n"; | ||
|
||
// Convert the stream to string | ||
$streams .= (string) $data['contents']; | ||
/* @var $contentStream StreamInterface */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good |
||
$contentStream = $data['contents']; | ||
if ($contentStream->isSeekable()) { | ||
$streams .= (string) $data['contents']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though the output it the same. I think I would like to change this line to: $streams .= $contentStream->_toString(); It will increase readability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great to hear you plan to merge the PR next week. I agree with your comment about readability and have made the change from string casting to explicitly calling __toString(). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome. Thank you. |
||
} else { | ||
$streams .= $contentStream->getContents(); | ||
} | ||
|
||
$streams .= "\r\n"; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
namespace tests\Http\Message\MultipartStream; | ||
|
||
use Http\Message\MultipartStream\MultipartStreamBuilder; | ||
use Zend\Diactoros\Stream; | ||
|
||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
|
@@ -15,7 +15,7 @@ public function testSupportStreams() | |
$body = 'stream contents'; | ||
|
||
$builder = new MultipartStreamBuilder(); | ||
$builder->addResource('foobar', $this->createStream($body)); | ||
$builder->addResource('foobar', $body); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This tests make sure we support a Stream. Please do not change this. |
||
|
||
$multipartStream = (string) $builder->build(); | ||
$this->assertTrue(false !== strpos($multipartStream, $body)); | ||
|
@@ -33,6 +33,21 @@ public function testSupportResources() | |
$this->assertTrue(false !== strpos($multipartStream, 'Content-Type: image/png')); | ||
} | ||
|
||
public function testSupportURIResources() | ||
{ | ||
$builder = new MultipartStreamBuilder(); | ||
$resource = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; | ||
$stream = fopen($resource, 'r'); | ||
$builder->addResource('image', $stream); | ||
$multipartStream = (string) $builder->build(); | ||
|
||
$this->assertTrue(false !== strpos($multipartStream, 'Content-Disposition: form-data; name="image"; filename="httplug.png"')); | ||
$this->assertTrue(false !== strpos($multipartStream, 'Content-Type: image/png')); | ||
|
||
$uriResourceContents = file_get_contents($resource); | ||
$this->assertContains($uriResourceContents, $multipartStream); | ||
} | ||
|
||
public function testResourceFilenameIsNotLocaleAware() | ||
{ | ||
// Get current locale | ||
|
@@ -116,18 +131,4 @@ public function testReset() | |
$this->assertNotEquals($boundary, $builder->getBoundary(), 'Stream should have a new boundary after reset()'); | ||
$this->assertNotEmpty($builder->getBoundary()); | ||
} | ||
|
||
/** | ||
* @param string $body | ||
* | ||
* @return Stream | ||
*/ | ||
private function createStream($body) | ||
{ | ||
$stream = new Stream('php://memory', 'rw'); | ||
$stream->write($body); | ||
$stream->rewind(); | ||
|
||
return $stream; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets change back to zend.