handle Optional and Required constraints from XML or YAML sources correc...

...tly

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7575
| License       | MIT
| Doc PR        | symfony/symfony-docs#2432