-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
[WIP] Streaming parser bufferedsink #73
[WIP] Streaming parser bufferedsink #73
Conversation
self::extractPost($postFields, $key, $value); | ||
}); | ||
$parser->on('file', function ($name, File $file) use (&$files) { | ||
StreamBufferedSink::createPromise($file->getStream())->then(function ($buffer) use ($name, $file, &$files) { |
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.
This should be done
instead of then
.
What about splitting this into 3 distinct sinks: a body, post and files sink. The sinks could be composed with parts you need. The resolution array from the current implementation could be achieved with $promises = [
'body' => BodyBufferedSink::createPromise($parser),
'post' => PostBufferedSink::createPromise($parser),
'files' => FilesBufferedSink::createPromise($parser),
];
React\Promise\all($promises)->done($result) {
// $result contains 'body', 'post' and 'files `entries
}); |
That is actually a great idea 👍 ! |
@jsor updated the PR with the split up |
use React\Http\Request; | ||
use React\Tests\Http\TestCase; | ||
|
||
class PostPostBufferedSinkTest extends TestCase |
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.
s/PostPost/Post
Maybe the class BufferedSink
{
/**
* @param ParserInterface $parser
* @return PromiseInterface
*/
public static function createPromise(ParserInterface $parser)
{
$promises = [
'body' => BodyBufferedSink::createPromise($parser),
'post' => PostBufferedSink::createPromise($parser),
'files' => FilesBufferedSink::createPromise($parser),
];
return Promise\all($promises);
}
} |
Just like the bufferedsink from stream and #70 but this sink takes a streaming body parser and buffers any post field, body data, or uploaded file. Once the full request it in the promise will resolve.
Depends on #69 and #62