Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

hvt
Copy link
Contributor

@hvt hvt commented Jun 20, 2012

No description provided.

@fabpot
Copy link
Member

fabpot commented Jul 1, 2012

Can you open a PR on symfony/symfony as this repository is read-only? Thanks.

@fabpot fabpot closed this Jul 2, 2012
symfony-splitter pushed a commit that referenced this pull request Sep 4, 2018
This PR was merged into the 4.2-dev branch.

Discussion
----------

Mark ExceptionInterfaces throwable #2

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This has been reverted in beta of 4.1 because of lack of support in prophecy, which has been fixed since then (incl. release). Can be merged again.

References:
symfony/symfony#26702
symfony/symfony#27420
symfony/symfony#27419
phpspec/prophecy#412

ping @dunglas @ciaranmcnulty @dkarlovi @Wirone @teohhanhui @stof @nicolas-grekas @ondrejmirtes

Commits
-------

17c3675226 Mark ExceptionInterfaces throwable
symfony-splitter pushed a commit that referenced this pull request Mar 9, 2024
…ys (Brajk19)

This PR was squashed before being merged into the 6.4 branch.

Discussion
----------

[Validator] UniqueValidator - normalize before reducing keys

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

In symfony/symfony#42403 checking for uniqueness of certain collection keys was enabled. Method `UniqueValidator::reduceElementKeys` removes all keys which are not specified.
Problem is that this happens before normalization, which in my opinion is not great because that method accepts array argument and if i have some object (DTO), TypeError will be thrown.

Example:

```php
class ParentDTO
{
    /**
     * `@var` ChildDTO[]
     */
    #[Assert\Unique(
        normalizer: [ChildDTO::class, 'normalize']
        fields: 'id'
    )]
    public array $children;
}
```

```php
class ChildDTO
{
    public string $id;
    public string $name;

    public static function normalize(self $obj): array
    {
        return [
            'id' => $obj->id,
            'name' => $obj->name
        ];
    }
}
```

Because normalization will happen after `reduceElementKeys` this will be thrown:
`TypeError: Symfony\Component\Validator\Constraints\UniqueValidator::reduceElementKeys(): Argument #2 ($element) must be of type array, ...\ChildDTO given, called in .../UniqueValidator.php on line 48`

If `$element = $normalizer($element);` is executed before `reduceElementKeys` it would enable using Assert\Unique with array of objects when correctly normalized

Commits
-------

77df90b959 [Validator] UniqueValidator - normalize before reducing keys
symfony-splitter pushed a commit that referenced this pull request Oct 11, 2024
* 7.1:
  do not mix named and positional arguments in data provider definitions
  session names must not be empty
  add missing properties
  fix Contracts directory name in PHPUnit configuration
  [Validator][CidrValidator] Fix error message for `OutOfRangeNetmask` validation
  Passing null to parameter #2 ($subject) of type string is deprecated
symfony-splitter pushed a commit that referenced this pull request Aug 12, 2025
* 7.4:
  [ObjectMapper] do not require mapping a target's required promoted property when not on source (#2)
  run tests with PHPUnit 12.3
  [GitHub] Update .github/PULL_REQUEST_TEMPLATE.md to remove SF 7.2 as it's not supported anymore
  [CI] fixed the Intl data tests actions Tests fails due to unknown option -v which is shorthand of the --verbose as per the phpunit its removed without any replacement sebastianbergmann/phpunit#5647 (comment)
  [Mailer] Fix expected exception message to include quotes around "http(s)://"
  [WebProfilerBundle] Fix toolbar not rendering after replacing it
  [Validator] (60455) Validate translations for Arabic (ar)
  (60474) Remove translation state attribute for Twig template validator in Ukrainian translation
  [VarDumper] Fix dumping objects from the DOM extension
  [Mailer] Add MicrosoftGraph API Transport
  [Yaml] Fix code style
  [Tests] Adapt testAddHtmlContentWithErrors to be HTML5 compliant
  Add friendly name in the `to` field
  [ObjectMapper] read source metadata before transform
  [HtmlSanitizer] Fix force_attributes not replacing existing attribute in initial data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants