affirmer Symfony

<?php

require_once '../vendor/autoload.php';

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Validation;

$validator = Validation::createValidator();

$input = [
    //'name' => [],
];

$notNestedConstraint = new Assert\Collection(
    [
        'first_name' => new Assert\Required(),
        'last_name' => new Assert\Required(),
    ],
);
$nestedConstraint = new Assert\Collection(
    [
        'name' => $notNestedConstraint,
    ]
);

$items = [];
$constraint = (array_key_exists('name', $input)) ? $nestedConstraint: $notNestedConstraint

$violations = $validator->validate($input, $constraint);
foreach ($violations as $violation) {
    $items[] = [
        'path' => $violation->getPropertyPath(),
        'message' => $violation->getMessage(),
    ];
}

var_dump($items);
SECRET MYSTERY