[Process] Accept Traversable input#18350
Conversation
nicolas-grekas
commented
Mar 29, 2016
| Q | A |
|---|---|
| Branch? | master |
| Bug fix? | no |
| New feature? | no |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #18262 |
| License | MIT |
| Doc PR | - |
4fb43fb to
c6485ee
Compare
| } | ||
|
|
||
| throw new InvalidArgumentException(sprintf('%s only accepts strings or stream resources.', $caller)); | ||
| throw new InvalidArgumentException(sprintf('%s only accepts strings, Traversable objects or stream resources.', $caller)); |
There was a problem hiding this comment.
technically, your code won't accept Traversable implemented in C without implementing Iterator, or implemented in PHP with IteratorAggregate returning such a traversable.
you should use IteratorIterator instead to wrap any Traversable into an Iterator.
8a72e3d to
5245bed
Compare
| { | ||
| $input = function ($data) { | ||
| while (false !== $data) { | ||
| $data = (yield $data); |
There was a problem hiding this comment.
HHVM doesn't seem to be happy with yield.
5245bed to
b3f382b
Compare
|
HHVM test fixed |
b3f382b to
b9782b7
Compare
|
Sounds very good ! Good job! |
|
|
||
| // no input to read on resource, buffer is empty | ||
| if (null === $this->input && !isset($this->inputBuffer[0])) { | ||
| if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) { |
There was a problem hiding this comment.
Why do we use isset() to test for the empty string instead of comparing it with the empty string like we usually do?
There was a problem hiding this comment.
because false is also a possible value here
|
👍 LGTM |
|
Thank you @nicolas-grekas. |
This PR was merged into the 3.1-dev branch. Discussion ---------- [Process] Accept Traversable input | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18262 | License | MIT | Doc PR | - Commits ------- b9782b7 [Process] Accept Traversable input