new ProjectConstraint to add dynamic project validation (#2747)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user