Re: RFC: Server-Side Request and Response Objects (v2)
| From: | Larry Garfield | Date: | Sat, 15 Feb 2020 08:01:59 +0000 |
| Subject: | Re: RFC: Server-Side Request and Response Objects (v2) | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108591@lists.php.net to get a copy of this message | ||
On Fri, Feb 14, 2020, at 10:47 AM, Benjamin Morel wrote:
> >
> > What about $query and $body? That would be closer to the terminology
> > used in HTTP RFCs.
>
>
>
> The problem is that $body is typically used to get the raw message body as
> a string or stream.
> I was thinking more something along the lines of $bodyParams, which is more
> verbose but leaves no ambiguity: *$queryParams* and *$bodyParams*.
>
> — Benjamin
Data point:
In PSR-7, the names used are:
- queryParams: The query string values.
- parsedBody: The body of the message, converted to a meaningful value. If the request type is a
form, then it MUST be equivalent to $_POST. If not, it's up to the particular implementation
to determine what "parsed" means. (Eg, parsing a JSON body of a POST into some domain
object, or whatever.)
- The raw body is a stream called "body", or rather an OOP wrapper around a stream since
PHP's native stream interface is fugly.
- There's specific handling for uploadedFiles, too.
cf: https://www.php-fig.org/psr/psr-7/
To the earlier point about existing implementations, while there are a myriad of older, custom
implementations of abstractions around superglobals, there's only two that are not decade-old
proprietary implementations: HttpFoundation and PSR-7. Those are, realistically, the only
implementations that matter. Anything else would be on the same order of magnitude effort to port
to one of those as to port to this proposal. In a meaningful sense, those are the only
"existing competition". Both also have robust ecosystems that make leveraging them in an
entirely custom app pretty straightforward.
(Whatever your feelings of the technical merits of either design, that's the current
state-of-the-market.)
Which therefore begs the question, is this proposal intended to supplant HttpFoundation and PSR-7,
or to become a common underpinning that both of them wrap, or to be a third cohabitating
implementation in the ecosystem?
It doesn't seem robust enough to supplant both of them entirely, there's little value to
either HttpFoundation or PSR-7 to rewrite their guts to wrap this object (though it's easier
for PSR-7, as an interface, for someone to write a new implementation of it than for
HttpFoundation), which would mean we'd end up with a 3rd in-the-wild implementation for user
space to keep track of.
I am unclear how that is a market win.
PDO was mentioned previously as a model. Yes, there were many user-space implementations prior to
PDO. PDO effectively supplanted and obsoleted them. However... PDO was also never thought-through
enough or robust enough to be used directly, spawning a whole new ecosystem of PDO++ libraries that
people actually use (Doctrine, Eloquent, Drupal's DBTNG, Aura..sql, to name but a few). So,
not the full win people were hoping for. If that pattern holds, we'd end up with... a new
generation of this-RFC++ wrappers that still abstract it away yet aren't compatible with each
other.
That said, PDO did have the advantage of at least partially unifying disparate SQL APIs. There
really aren't multiple incompatible HTTPs to abstract over the way there is for SQL backends,
so the analogy is somewhat weak either way.
--Larry Garfield