Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Validator] Fixed string conversion in constraint violations#10687

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
webmozart merged 12 commits intosymfony:2.3fromwebmozart:issue10677
Jul 30, 2014

Conversation

webmozart
Copy link
Contributor

QA
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#10675
LicenseMIT
Doc PR-

}

if (is_array($value)) {
return 'Array';
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add the array size likeArray(2) since Object and Resource also add further data

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I don't really like that writing, sinceArray(2) is the output ofprint_r when an array contains only the value2 and might cause confusion.

Copy link
Contributor

Choose a reason for hiding this comment

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

print_r returnsArray ( [0] => 2 )

Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't see the usefulness of this return value. It should format the value, i.e. the contents, but it basically returns the same asformatTypeOf. It returns the type and not the contents of the array. So it does not add anything new. So ideally it should output a concise representation of the array like['foo', 1, 'Object(Author)']. Or at least the array size as I suggested above.

Imagine the this is used in theCountValidator.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I don't think this valueneeds to be very useful. In most cases, validation messages are displayed to the end user. Displaying something like['foo', 1, 'Object(Author)'] to an average end users frightens them because they think something is broken.

Developers can always call$violation->getInvalidValue() to analyze the value in detail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Resource ID and object class are also implementation detail not intended for end users.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with both of you@webmozart and@Tobion!

If this is displayed to the end users, we should not be too precise; so the resource id is not needed, but I would even say that displayingarray,object, orresource to the end user looks weird as he probably did not enter that in a form value anyway.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ok, I will change these outputs to just "array", "object" and "resource" then. I agree that this doesn't help end users very much. I'd even go further to say that messagesshould never include the value if that value is one of these types. If developers choose to include the value in the message anyway, the displayed information will be minimal.

@webmozart
Copy link
ContributorAuthor

Updated.

protected function valuesToString(array $values, $formatDates = false)
{
foreach ($values as $key => $value) {
$values[$key] = $this->valueToString($value, $formatDates);
Copy link
Contributor

Choose a reason for hiding this comment

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

indexing by $key should not be necessary

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Can you clarify what you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm, didn't see you replace the interated array values. Maybe using another array like$convertedValues[] = ... would be cleaner.

@webmozart
Copy link
ContributorAuthor

I now introduced calls toformatValue() (formervalueToString()) everywhere that it makes sense to me.

*
* @return string
*/
protected function formatValues(array $values, $formatDates = false)
Copy link
Contributor

Choose a reason for hiding this comment

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

informatValue the parameter is named$prettyDateTime. Seems incosistent at the moment.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks! Fixed

webmozart added a commit to webmozart/symfony that referenced this pull requestJul 28, 2014
…e is an array, object or resourceThis was decided in the discussion ofsymfony#10687.
@webmozart
Copy link
ContributorAuthor

Updated.

cleentfaar pushed a commit to cleentfaar/symfony that referenced this pull requestJul 29, 2014
cleentfaar pushed a commit to cleentfaar/symfony that referenced this pull requestJul 29, 2014
}

/**
* Returns a string representation of the value.
Copy link
Member

Choose a reason for hiding this comment

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

Could you add some more explanations about when/why/how this is ever called? Something along the lines of:

"This method is used when a constraint error message contains the {{ value }} placeholder. By default, Symfony never includes it, but the developer can override those error messages. It's up to the developer to make sure it actually makes sense to include such string representation of submitted values in error messages."

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done

@fabpot
Copy link
Member

👍

1 similar comment
@Tobion
Copy link
Contributor

👍

@webmozartwebmozart merged commit32ae95b intosymfony:2.3Jul 30, 2014
webmozart added a commit that referenced this pull requestJul 30, 2014
…ns (eagleoneraptor, webmozart)This PR was merged into the 2.3 branch.Discussion----------[Validator] Fixed string conversion in constraint violations| Q             | A| ------------- | ---| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#10675| License       | MIT| Doc PR        | -Commits-------32ae95b [Validator] Added more detailed inline documentation08ea6d3 [Validator] Removed information from the violation output if the value is an array, object or resourced6a783f [Validator] Renamed valueToString() to formatValue(); added missing formatValue() calls71897d7 [Validator] Fixed CScea4155 [Validator] Fixed date-to-string conversion tests to match ICU 515aa7e6d [Validator] Added "{{ value }}" parameters where they were missingf329552 [Validator] Simplified and explained the LuhnValidatorbff09f2 [Validator] Simplified IssnValidator224e70f [Validator] Fixed and simplified IsbnValidatorfd58870 [Validator] Simplified IBAN validation algorithm97243bc [Validator] Fixed value-to-string conversion in constraint violations75e8815 [Validator] Fix constraint violation message parameterization
@webmozartwebmozart deleted the issue10677 branchAugust 4, 2014 14:42
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@webmozart@fabpot@Tobion@dnohales

[8]ページ先頭

©2009-2025 Movatter.jp