-
-
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
Streaming body parser: Form Urlencoded #202
Streaming body parser: Form Urlencoded #202
Conversation
Next PR will add streaming body parser documentation to |
public function __construct(RequestInterface $request) | ||
{ | ||
$this->request = $request; | ||
$this->body = $this->request->getBody(); |
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.
Maybe check here if $this->body
is an instance of HttpBodyStream
?
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.
WDYT? Since the class isn't internal, it isn't guaranteed that $this->body
is an instance of HttpBodyStream
.
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.
I'm thinking a check on if body is a ReadableStreamInterface
and else throw an exception.
* | ||
* @internal | ||
*/ | ||
public $body; |
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.
private
?
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.
Nope because of PHP 5.3 here https://github.com/WyriHaximus/http/blob/97ade3db7e4b1fe079cff9a6643e61975e179b59/src/StreamingBodyParser/FormUrlencodedParser.php#L39-L43 or I could make a public onEnd
method, mark it private and make everything that shouldn't be public
private
.
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.
Yes, you're correct. My bad 🤗
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.
I'll look into refactoring it a bit anyway 👍
* | ||
* @internal | ||
*/ | ||
public $buffer = ''; |
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.
private
?
/** | ||
* @internal | ||
*/ | ||
public function parse($buffer) |
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.
private
?
foreach (explode('&', $buffer) as $chunk) { | ||
$this->emit( | ||
'post', | ||
explode('=', rawurldecode($chunk)) |
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.
Not sure, but maybe ensure here that there will be always an array with to entries (key and value) emitted. so that key1&key2
emits array('key1', null)
and array('key2', null
)`?
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.
Good point 👍
@WyriHaximus superseded by #222? |
Related to #200 this adds the form urlencoded parser.