Skip to content

[HttpFoundation] [WIP] rename Request::$request to $post #47938

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

Closed
wants to merge 1 commit into from

Conversation

kbond
Copy link
Member

@kbond kbond commented Oct 20, 2022

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? yes
Tickets #47646
License MIT
Doc PR todo

This should alleviate the confusion of what $request->request is.

TODO:

  • deprecation layer(?)
  • update changelog

@carsonbot carsonbot added this to the 6.2 milestone Oct 20, 2022
@carsonbot carsonbot changed the title [WIP][HttpFoundation] rename Request::$request to $form [HttpFoundation] [WIP] rename Request::$request to $form Oct 20, 2022
@kbond
Copy link
Member Author

kbond commented Oct 20, 2022

I could use some advise on how to create a deprecation layer for this. To avoid a BC break, Request::$request and Request::$form must reference the same InputBag instance.

Also, since $request/$form are public and writable, you can change one without the other...

Could we use __set()/__get() to provide a deprecation layer?

@kbond kbond removed the Bug label Oct 20, 2022
@kbond
Copy link
Member Author

kbond commented Oct 20, 2022

FYI, I chose $form because this is what $_POST represents, the form data. I'm not completely convinced that $form is the best term (it's better than $request IMO) - maybe $post or $postData would be better?

@kbond kbond modified the milestones: 6.2, 6.3 Oct 20, 2022
*
* @var InputBag
*/
public $form;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about naming it $postData?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the word data is implicit via the $request object no?
a request (class) transferring a data via http (foundation)
to me $post is good candidate :)

@stof
Copy link
Member

stof commented Oct 21, 2022

To me, $request->form is an equally bad name. <form method="get"> would not put its data in the form property

@94noni
Copy link
Contributor

94noni commented Oct 21, 2022

@kbond you can organize a pool on slack or here to get some community feedbacks on "proper" new naming
I like $post for representing $_post

@@ -89,10 +89,19 @@ class Request
/**
* Request body parameters ($_POST).
*
* @deprecated since Symfony 6.2
*
* @var InputBag
*/
public $request;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be implemented through __get and __set, to avoid issue where someone re-assign the property, where we would have different instances in the new property and the old one (breaking the BC layer)

@alexander-schranz
Copy link
Contributor

alexander-schranz commented Oct 21, 2022

Personally don't think its worth renaming this. This will be a hard break for a lot of Systems, which tries in the past supporting multiple Symfony versions.

And if I would more go with something based on the http specification. I think there it is also sometimes represented as request, but also as Content / Message or Body. For me form is more confusing then request as a form is GET or POST in HTML and the request data is more for PUT, DELETE, PATCH, ...

In PSR7 it is referenced as getParsedBody so I think body sould reference best, else the same problem I think will exist with other name if we don't make it similar to other existing standard.

@kbond
Copy link
Member Author

kbond commented Oct 22, 2022

Personally don't think its worth renaming this. This will be a hard break for a lot of Systems, which tries in the past supporting multiple Symfony versions.

This is fair. Maybe we could have a longer deprecation cycle? Remove $request in Symfony 8?

Seems like $post would be a good candidate and I agree.

@kbond kbond changed the title [HttpFoundation] [WIP] rename Request::$request to $form [HttpFoundation] [WIP] rename Request::$request to $post Oct 22, 2022
@kbond kbond added the RFC RFC = Request For Comments (proposals about features that you want to be discussed) label Oct 22, 2022
@wouterj
Copy link
Member

wouterj commented Oct 22, 2022

My 2-cents:

What I liked about the original proposal in #47646 is the fact that we don't have to deprecate $request->request. We add a new property (name tbd), which covers the functionality of $request->request on top of extended functionality (parsing more request body content types, whereas $request->request only "parses" application/x-www-form-urlencoded related content types).

This means we don't deprecate $request->request (i.e. no impact on existing apps), but we update the docs to use the new property instead.

Duplicating what I said on Slack: the HTTP spec calls this "request payload body", maybe $request->payload is a nice name?

@GromNaN
Copy link
Member

GromNaN commented Oct 27, 2022

  • 👍🏻 for naming $request->payload. This is the name in the RFC 7231 and Chrome Dev Tools.
  • 👍🏻 for keeping the existing $request->request untouched for BC. The new field will have a new behavior.

Additionally, $request->payload should be lazy-loaded: JSON decode should be done only when requested and throw BadRequestException in case of invalid format.

@kbond
Copy link
Member Author

kbond commented Dec 7, 2022

Ok, I'm going to update this PR to just add Request::$payload. Instead of a new property, what about a Request::getPayload() method instead? This could avoid the need for a LazyParameterBag.

@luxferoo
Copy link

@kbond Thank you for the great work ! When do you think it would be available please ?

@kbond
Copy link
Member Author

kbond commented Jan 25, 2023

I'm hoping to get rework this soon and try and get it into 6.3.

@nicolas-grekas
Copy link
Member

closing in favor of #49614

fabpot added a commit that referenced this pull request Apr 20, 2023
This PR was merged into the 6.3 branch.

Discussion
----------

[HttpFoundation] add `Request::getPayload()`

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #47646
| License       | MIT
| Doc PR        | todo

Alternative for #47938 based on feedback there.

```php
/** `@var` InputBag $input wrapping either Request::$request or Request::toArray() */
$input = $request->getPayload();
```

Commits
-------

4a0a439 [HttpFoundation] add `Request::getPayload()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecation Feature HttpFoundation RFC RFC = Request For Comments (proposals about features that you want to be discussed) Status: Needs Work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants