Skip to content

[HttpFoundation] replace $request->request by $request->getPayload() #19225

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ the ``Request`` class::

// retrieves GET and POST variables respectively
$request->query->get('page');
$request->request->get('page');
$request->getPayload()->get('page');

// retrieves SERVER variables
$request->server->get('HTTP_HOST');
Expand Down
2 changes: 1 addition & 1 deletion create_framework/http_foundation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fingertips thanks to a nice and simple API::

// retrieves GET and POST variables respectively
$request->query->get('foo');
$request->request->get('bar', 'default value if bar does not exist');
$request->getPayload()->get('bar', 'default value if bar does not exist');

// retrieves SERVER variables
$request->server->get('HTTP_HOST');
Expand Down
6 changes: 3 additions & 3 deletions form/direct_submit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ control over when exactly your form is submitted and what data is passed to it::
$form = $this->createForm(TaskType::class, $task);

if ($request->isMethod('POST')) {
$form->submit($request->request->all($form->getName()));
$form->submit($request->getPayload()->get($form->getName()));

if ($form->isSubmitted() && $form->isValid()) {
// perform some action...
Expand All @@ -41,7 +41,7 @@ the fields defined by the form class. Otherwise, you'll see a form validation er
if ($request->isMethod('POST')) {
// '$json' represents payload data sent by React/Angular/Vue
// the merge of parameters is needed to submit all form fields
$form->submit(array_merge($json, $request->request->all()));
$form->submit(array_merge($json, $request->getPayload()->all()));

// ...
}
Expand Down Expand Up @@ -73,4 +73,4 @@ the fields defined by the form class. Otherwise, you'll see a form validation er
manually so that they are validated::

// 'email' and 'username' are added manually to force their validation
$form->submit(array_merge(['email' => null, 'username' => null], $request->request->all()), false);
$form->submit(array_merge(['email' => null, 'username' => null], $request->getPayload()->all()), false);
2 changes: 1 addition & 1 deletion form/without_class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ an array.
You can also access POST values (in this case "name") directly through
the request object, like so::

$request->request->get('name');
$request->getPayload()->get('name');

Be advised, however, that in most cases using the ``getData()`` method is
a better choice, since it returns the data (usually an object) after
Expand Down
2 changes: 1 addition & 1 deletion html_sanitizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ automatically when type-hinting for
{
public function createAction(HtmlSanitizerInterface $htmlSanitizer, Request $request): Response
{
$unsafeContents = $request->request->get('post_contents');
$unsafeContents = $request->getPayload()->get('post_contents');

$safeContents = $htmlSanitizer->sanitize($unsafeContents);
// ... proceed using the safe HTML
Expand Down
2 changes: 1 addition & 1 deletion introduction/http_fundamentals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ have all the request information at your fingertips::

// retrieves $_GET and $_POST variables respectively
$request->query->get('id');
$request->request->get('category', 'default category');
$request->getPayload()->get('category', 'default category');

// retrieves $_SERVER variables
$request->server->get('HTTP_HOST');
Expand Down
2 changes: 1 addition & 1 deletion security/csrf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ method to check its validity::

public function delete(Request $request): Response
{
$submittedToken = $request->request->get('token');
$submittedToken = $request->getPayload()->get('token');

// 'delete-item' is the same value used in the template to generate the token
if ($this->isCsrfTokenValid('delete-item', $submittedToken)) {
Expand Down
6 changes: 3 additions & 3 deletions security/custom_authenticator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ would initialize the passport like this::
{
public function authenticate(Request $request): Passport
{
$password = $request->request->get('password');
$username = $request->request->get('username');
$csrfToken = $request->request->get('csrf_token');
$password = $request->getPayload()->get('password');
$username = $request->getPayload()->get('username');
$csrfToken = $request->getPayload()->get('csrf_token');

// ... validate no parameter is empty

Expand Down
4 changes: 2 additions & 2 deletions security/login_link.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ this interface::
// check if form is submitted
if ($request->isMethod('POST')) {
// load the user in some way (e.g. using the form input)
$email = $request->request->get('email');
$email = $request->getPayload()->get('email');
$user = $userRepository->findOneBy(['email' => $email]);

// create a login link for $user this returns an instance
Expand Down Expand Up @@ -228,7 +228,7 @@ number::
public function requestLoginLink(NotifierInterface $notifier, LoginLinkHandlerInterface $loginLinkHandler, UserRepository $userRepository, Request $request): Response
{
if ($request->isMethod('POST')) {
$email = $request->request->get('email');
$email = $request->getPayload()->get('email');
$user = $userRepository->findOneBy(['email' => $email]);

$loginLinkDetails = $loginLinkHandler->createLoginLink($user);
Expand Down