@@ 11-33 (lines=23) @@ | ||
8 | /** |
|
9 | * @author Vehsamrak |
|
10 | */ |
|
11 | class EntityDoesNotExistsValidator extends EntityValidator |
|
12 | { |
|
13 | ||
14 | /** |
|
15 | * @param mixed $entityFieldValue |
|
16 | * @param EntityDoesNotExists $constraint |
|
17 | */ |
|
18 | public function validate($entityFieldValue, Constraint $constraint) |
|
19 | { |
|
20 | $this->checkAnnotationParameters($constraint); |
|
21 | ||
22 | $entity = $this->findEntity($entityFieldValue, $constraint); |
|
23 | $entityName = (new \ReflectionClass($constraint->entityClass))->getShortName(); |
|
24 | ||
25 | if ($entity) { |
|
26 | $this->context->buildViolation($constraint->message) |
|
27 | ->setParameter('%entityName%', $entityName) |
|
28 | ->setParameter('%field%', $constraint->entityField) |
|
29 | ->setParameter('%fieldValue%', $entityFieldValue) |
|
30 | ->addViolation(); |
|
31 | } |
|
32 | } |
|
33 | } |
|
34 |
@@ 11-33 (lines=23) @@ | ||
8 | /** |
|
9 | * @author Vehsamrak |
|
10 | */ |
|
11 | class EntityExistsValidator extends EntityValidator |
|
12 | { |
|
13 | ||
14 | /** |
|
15 | * @param mixed $entityFieldValue |
|
16 | * @param EntityDoesNotExists $constraint |
|
17 | */ |
|
18 | public function validate($entityFieldValue, Constraint $constraint) |
|
19 | { |
|
20 | $this->checkAnnotationParameters($constraint); |
|
21 | ||
22 | $entity = $this->findEntity($entityFieldValue, $constraint); |
|
23 | $entityName = (new \ReflectionClass($constraint->entityClass))->getShortName(); |
|
24 | ||
25 | if (!$entity) { |
|
26 | $this->context->buildViolation($constraint->message) |
|
27 | ->setParameter('%entityName%', $entityName) |
|
28 | ->setParameter('%field%', $constraint->entityField) |
|
29 | ->setParameter('%fieldValue%', $entityFieldValue) |
|
30 | ->addViolation(); |
|
31 | } |
|
32 | } |
|
33 | } |
|
34 |