Skip to content

Conversation

@Majkl578
Copy link
Contributor

BC break (deprecation of $rawBodyCallback in constructor)
I'd also remove NULL on empty data and return empty string, but I'm not sure about implications in user-land...

Depends on #70 (composer.json & Travis).

@JanTvrdik
Copy link
Contributor

👎 The previous implementation was cleaner. Http\Request should not directly read php://input.

@Majkl578
Copy link
Contributor Author

Cleaner in what way? It just always directly called php://input, also it was not type safe (no signature contract).

@JanTvrdik
Copy link
Contributor

Request should not read global state.

@jkuchar
Copy link

jkuchar commented Aug 24, 2015

Agree, current implementation is easier to mock.

@Majkl578
Copy link
Contributor Author

I agree that it should not read global state.

But current implementation is just a hack because php://input was not rewindable in <5.6. Closure callback is not type safe, could not be properly type hinted and relied upon (especially in PHP 7) or unit tested on its own. (Unit tests for closure? Sounds weird.)

I also had another solution in mind, except obvious option to introduce an interface (sounds unnecessary), an option to provide a stream address php://input via constructor. It could be easily mocked/tested as well. And also provide an option to return it as a resource instead of string copy (this is also what Symfony supports).
But I think it is out of scope of this PR.

@JanTvrdik
Copy link
Contributor

But current implementation is just a hack because

Nope. I wrote the current implementation and the callback is here because "Request should not read global state". The hack was there before the callback.

Closure callback is not type safe

Which noone really cares about, this is PHP. Request is low-level class, most people don't care about the constructor.

@Majkl578
Copy link
Contributor Author

If you don't care about constructor, why not just pass resource then?

@JanTvrdik
Copy link
Contributor

That was considered, but doing so in PHP < 5.6 is AFAIK very difficult to do reliably and efficiently. Doing so now is an unnecessary BC break for no clear gain.

@Majkl578
Copy link
Contributor Author

Sure, it would be a little BC break (funny, considering all the PHP 5.6/7.0 changes that are coming), but as you said, for a low level class where almost noone cares about the constructor.

@JanTvrdik
Copy link
Contributor

But what would we gain with such BC break? Support for processing large post bodies? Maybe.

Assuming there is no performance penalty for passing STDIN constant, we may add getRawBodyStream() which would return resource and keep getRawBody() which will return string with stream_get_contents. Note that you can not typehint resource either.

@dg dg closed this Oct 9, 2015
@dg
Copy link
Member

dg commented Oct 9, 2015

Implemented in this way 0f5cee3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants