Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Process] Accept Traversable input #18350

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

Merged
merged 1 commit into from
Mar 31, 2016

Conversation

nicolas-grekas
Copy link
Member

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 -


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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas nicolas-grekas force-pushed the proc-input-stream branch 3 times, most recently from 8a72e3d to 5245bed Compare March 29, 2016 17:09
@nicolas-grekas nicolas-grekas changed the title [Process] Handle Iterator as input [Process] Accept Traversable input Mar 29, 2016
{
$input = function ($data) {
while (false !== $data) {
$data = (yield $data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HHVM doesn't seem to be happy with yield.

@nicolas-grekas
Copy link
Member Author

HHVM test fixed

@romainneutron
Copy link
Contributor

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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use isset() to test for the empty string instead of comparing it with the empty string like we usually do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because false is also a possible value here

@xabbuh
Copy link
Member

xabbuh commented Mar 31, 2016

👍 LGTM

@fabpot
Copy link
Member

fabpot commented Mar 31, 2016

Thank you @nicolas-grekas.

@fabpot fabpot merged commit b9782b7 into symfony:master Mar 31, 2016
fabpot added a commit that referenced this pull request Mar 31, 2016
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
@nicolas-grekas nicolas-grekas deleted the proc-input-stream branch March 31, 2016 07:38
@fabpot fabpot mentioned this pull request May 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants