Skip to content
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

feat: [Validation] add method to get the validated data #7420

Merged
merged 6 commits into from
Apr 12, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Apr 11, 2023

Description

  • add Validation::getValidated()

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added enhancement PRs that improve existing functionalities 4.4 labels Apr 11, 2023
@kenjis kenjis changed the title feat: add method to get the validated data feat: [Validation] add method to get the validated data Apr 11, 2023
@iRedds
Copy link
Collaborator

iRedds commented Apr 11, 2023

I'd like to hear the reason for adding this method.
What is the real benefit of it?

@kenjis
Copy link
Member Author

kenjis commented Apr 11, 2023

Security enhancement.
This method returns only validated data, so developers can be sure to use validated data.

@iRedds
Copy link
Collaborator

iRedds commented Apr 11, 2023

Let's say the script receives data, some of which do not need to be validated.
It turns out that after validation, the getValidated() method will return only part of the data, which will add an extra operation to manipulate the data further.
For me, this feature looks dubious.

@kenjis
Copy link
Member Author

kenjis commented Apr 11, 2023

Let's say the script receives data, some of which do not need to be validated.

This method is intended for input validation like validation for HTML form.
What data don't you need to validate?

@ddevsr
Copy link
Collaborator

ddevsr commented Apr 11, 2023

For me, currently develop upload batch by excel and will return callback failed excel with marker like alreadyExists in column description.

Upload:

1|John Doe|2023-02-01|
2|Maria|2024-04-14|

Callback:

1|John Doe|2023-02-01|DONE
2|Maria|2024-04-14|alreadyExists

I think this function can use for this case and combine failed validation

@kenjis
Copy link
Member Author

kenjis commented Apr 12, 2023

Added the docs.

];

if ($validation->run($data)) {
$validatedData = $validation->getValidated();
Copy link
Member

Choose a reason for hiding this comment

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

This example is fine, but I would like to ask you to add an example that will cover controller validation (with the $this->validate() method). This is the place where this method is the most valuable.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a plan to add a method to get validated data in Controller, and update all sample code with $this->validate().

Copy link
Member

Choose a reason for hiding this comment

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

I don't think need a separate method in the controller for this, though.
Since we can get the errors via $this->validator->getErrors(), I see no problem with getting validated data the same way, via $this->validator->getValidated().

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I see. Thank you for opinion.

Copy link
Member Author

Choose a reason for hiding this comment

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

See #7425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.4 enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants