Skip to content

Commit

Permalink
Merge pull request #992 from bravik/fix-composite-validation-constraints
Browse files Browse the repository at this point in the history
Fix type generation for Composite symfony validator with explicit 'constraints' key
  • Loading branch information
mcg-web committed Mar 4, 2022
2 parents f3b2357 + 8c5c685 commit c39a52a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Generator/TypeBuilder.php
Expand Up @@ -637,6 +637,21 @@ protected function buildConstraints(array $constraints = [], bool $inClosure = t
if (isset($args[0]) && is_array($args[0])) {
// Nested instance
$instance->addArgument($this->buildConstraints($args, false));
} elseif (isset($args['constraints'][0]) && is_array($args['constraints'][0])) {
// Nested instance with "constraints" key (full syntax)
$options = [
'constraints' => $this->buildConstraints($args['constraints'], false),
];

// Check for additional options
foreach ($args as $key => $option) {
if ('constraints' === $key) {
continue;
}
$options[$key] = $option;
}

$instance->addArgument($options);
} else {
// Numeric or Assoc array?
$instance->addArgument(isset($args[0]) ? $args : Collection::assoc($args));
Expand Down

0 comments on commit c39a52a

Please sign in to comment.