new ProjectConstraint to add dynamic project validation (#2747)

This commit is contained in:
pkaltenboeck
2021-11-14 16:56:52 +01:00
committed by GitHub
parent a483184372
commit dce0578a2b
4 changed files with 45 additions and 0 deletions

View File

@@ -18,6 +18,19 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class ProjectValidator extends ConstraintValidator
{
/**
* @var Constraint[]
*/
private $constraints;
/**
* @param Constraint[] $constraints
*/
public function __construct(iterable $constraints = [])
{
$this->constraints = $constraints;
}
/**
* @param Project|mixed $value
* @param Constraint $constraint
@@ -33,6 +46,13 @@ class ProjectValidator extends ConstraintValidator
}
$this->validateProject($value, $this->context);
foreach ($this->constraints as $constraint) {
$this->context
->getValidator()
->inContext($this->context)
->validate($value, $constraint, [Constraint::DEFAULT_GROUP]);
}
}
protected function validateProject(Project $project, ExecutionContextInterface $context)