-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] use InputBag for Request::$request only if data is coming from a form #37265
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ class Request | |
/** | ||
* Request body parameters ($_POST). | ||
* | ||
* @var InputBag | ||
* @var InputBag|ParameterBag | ||
*/ | ||
public $request; | ||
|
||
|
@@ -268,7 +268,7 @@ public function __construct(array $query = [], array $request = [], array $attri | |
*/ | ||
public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null) | ||
{ | ||
$this->request = new InputBag($request); | ||
$this->request = new ParameterBag($request); | ||
$this->query = new InputBag($query); | ||
$this->attributes = new ParameterBag($attributes); | ||
$this->cookies = new InputBag($cookies); | ||
|
@@ -298,7 +298,9 @@ public static function createFromGlobals() | |
{ | ||
$request = self::createRequestFromFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER); | ||
|
||
if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') | ||
if ($_POST) { | ||
$request->request = new InputBag($_POST); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of the developers using symfony that will create a form using
So I don't see this InputBag here serving the majority.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The form component is already strict about strings vs arrays in values and knows how to deal with InputBag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes the form component, as a component knows how to deal with the InputBag.. my point is that users that will build a form with the component... they will never use this:
What use cases/bugs are you trying to cover by using for the
All this started with the scenario that someone access a query parameter and thinking that it is string etc etc.. ok.. although I disagree with the notion of it.. it is a UseCase. I don't see how developers will be protected by using All I see is that I have to do this: $login = $request->request->get('login');
return \is_array($login) && isset($login['username']) && isset($login['password']) && isset($login['_token']); to: $request = $request->request->all();
if (!isset($request['login'])) {
return false;
}
$login = $request['login'];
return \is_array($login) && isset($login['username']) && isset($login['password']) && isset($login['_token']); it's not the code that I have to write.. it's that Hope I am explaining in the best way.. if not.. maybe we should move on.. there might be more important things to care.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your "to" should be: $request = $request->request->all('login');
return isset($login['username']) && isset($login['password']) && isset($login['_token']); Then you'll let a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I can't.. various technical reasons that are out of the topic of this discussion... Still this remains:
|
||
} elseif (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') | ||
&& \in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH']) | ||
) { | ||
parse_str($request->getContent(), $data); | ||
|
@@ -447,7 +449,7 @@ public function duplicate(array $query = null, array $request = null, array $att | |
$dup->query = new InputBag($query); | ||
} | ||
if (null !== $request) { | ||
$dup->request = new InputBag($request); | ||
$dup->request = new ParameterBag($request); | ||
} | ||
if (null !== $attributes) { | ||
$dup->attributes = new ParameterBag($attributes); | ||
|
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 see that you tried making the behavior between the two bags more similar.. nice.. not sure if you were driven by my comment... but this is indeed nice..
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 don't remember exactly my flow of thoughts, but it might be :)