-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[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
Changes from all commits
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 |
---|---|---|
|
@@ -93,8 +93,14 @@ public static function validateInput($caller, $input) | |
if (is_scalar($input)) { | ||
return (string) $input; | ||
} | ||
if ($input instanceof \Iterator) { | ||
return $input; | ||
} | ||
if ($input instanceof \Traversable) { | ||
return new \IteratorIterator($input); | ||
} | ||
|
||
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. Choose a reason for hiding this commentThe 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 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. Fixed
|
||
} | ||
|
||
return $input; | ||
|
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.
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.
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