Re: [PHP-DEV] RFC: Server-Side Request and Response Objects (v2)

This is only part of a thread. view whole thread
  108657
February 18, 2020 13:33 pmjones@pmjones.io ("Paul M. Jones")
Hi Côme,

> On Feb 18, 2020, at 03:24, Côme Chilliet chilliet@fusiondirectory.org> wrote: > > Le jeudi 13 février 2020, 09:16:49 CET Paul M. Jones a écrit : > >> Yeah, naming is one of the hard problems. I considered $query as an alternative property name for $get, but in the end, the `$_GET => $get` symmetry was too great to ignore. If others here feel that $query is a better name for `$_GET` than $get, I will submit to consensus on that point. > > query is definitely better than get.
Excellent.
> Regarding post, I’m fine with body, parsedBody and input. > > I get the idea of input to mimic php://input, but if I understand things correctly, php://input is raw body, while $request->post is parsed body, so naming them alike might actually cause confusion?
Might, might not. I don't think there is any "good" name here, only names that are less-bad than others.
> I still do not understand this. > echo adds content to the response, it does not replace it. > So the equivalent function should be $response->addContent. > > I would expect $response->setContent to replace the content.
Ah, I see what you are getting at now ...
> Can you explicit behavior for this: > > $response->setContent("a\n"); > $response->setContent("b\n"); > $responseSender->send($response); > > Compared to > > echo "a\n"; > echo "b\n";
.... the output would be "b\n". As you say, setContent() replaces whatever content is already in the ServerResponse. While the comparison for a single echo is accurate, the comparison for multiple echoes would be: $content = "a\n"; $content .= "b\n"; $response->setContent($content); $responseSender->send($content); Does that help to clarify? -- Paul M. Jones pmjones@pmjones.io http://paul-m-jones.com Modernizing Legacy Applications in PHP https://leanpub.com/mlaphp Solving the N+1 Problem in PHP https://leanpub.com/sn1php
  108659
February 18, 2020 14:10 come.chilliet@fusiondirectory.org (=?ISO-8859-1?Q?C=F4me?= Chilliet)
Le mardi 18 février 2020, 07:33:37 CET Paul M. Jones a écrit :
> ... the output would be "b\n". As you say, setContent() replaces whatever content is already in the ServerResponse. While the comparison for a single echo is accurate, the comparison for multiple echoes would be: > > $content = "a\n"; > $content .= "b\n"; > $response->setContent($content); > $responseSender->send($content); > > Does that help to clarify?
Yes, but to me that means we also need an addContent method. Otherwise people will have to carry a global $content along side $response, or use setContent(getContent().$additionalContent). -- Côme Chilliet FusionDirectory - https://www.fusiondirectory.org
  108660
February 18, 2020 14:56 pmjones@pmjones.io ("Paul M. Jones")
> On Feb 18, 2020, at 08:10, Côme Chilliet chilliet@fusiondirectory.org> wrote: > > to me that means we also need an addContent method.
I can see why we'd think that; it's symmetrical, if nothing else. Even so, none of the researched implementations have a method like that. As far as I can recall, they call have setContent() and getContent() equivalents, but no addContent() equivalent. They all work much like you point out here ...
> Otherwise people will have to carry a global $content along side $response, or use setContent(getContent().$additionalContent).
.... although usually it's not a global $content. Instead, the $content is built up from a template or other subsystem of some sort, and then assigned to the response when complete. For example: $content = $template->render(); $response->setContent($content); So, I am reluctant to add something that no other implementations, across many years and many authors, have actually found a need for. Any further thoughts on this? -- Paul M. Jones pmjones@pmjones.io http://paul-m-jones.com Modernizing Legacy Applications in PHP https://leanpub.com/mlaphp Solving the N+1 Problem in PHP https://leanpub.com/sn1php