-
Notifications
You must be signed in to change notification settings - Fork 39
Add buffered stream #52
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
Conversation
private $stream; | ||
|
||
/** @var int How many bytes were written */ | ||
private $writed = 0; |
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.
should be named to $written
$this->rewind(); | ||
|
||
return $this->getContents(); | ||
} catch (\Throwable $throwable) { |
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.
isn't this php 7 only? ah if it does not exist, php 5 will ignore this and use the catch below. maybe add a comment below that thats only for BC with php 5 and can be removed when going to php 7
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.
done
Is it ok to merge ? |
looks good to me. @Nyholm @sagikazarmark do you agree? |
AFAIK there are some PSR7 compliance test suits out there. Maybe we should use them to test PSR7 implementations. If they are not good enough, maybe we could write one? Apart from that, LGTM. |
👍 |
more testing is always good, but lets not hold up merging. @joelwurtz if you have time to check out the idea from mark, that would be great to detect issues before we release. |
I only found https://github.com/Maks3w/Psr7Assertions but this does not test stream |
I was once thinking about writting a PSR7 tester lib which accepts message factories to create messages/streams so that it can handle specific data and other options. The other possibility is to have an abstract method which returns a PSR7 object instance and that can be used since its immutable, although there would be some drawbacks like streams are noz immutable, etc. |
This is a replacement for the MemoryCloner, this allow to decorate a not seekable stream with a seekable one.
In order to do that it buffer the underlying stream into a php://temp resource by default (but can also be fully buffered into memory).
It never reads the underlying stream, until it has been tell to do so.
Once this is merged i will add a EnsureSeekableStreamPlugin, which decorates the request body and the response body with this one if the existing stream is not seekable, so we would be able to get the stream content (format) even for not seekable stream (only if user want it).