| @@ 14-45 (lines=32) @@ | ||
| 11 | /** |
|
| 12 | * @Annotation |
|
| 13 | */ |
|
| 14 | class LeadExistValidator extends ConstraintValidator |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * @var LeadRepository |
|
| 18 | */ |
|
| 19 | protected $repositoryLead; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * NotCreatedSameLeadValidator constructor. |
|
| 23 | * @param LeadRepository $repositoryLead |
|
| 24 | */ |
|
| 25 | public function __construct(LeadRepository $repositoryLead) |
|
| 26 | { |
|
| 27 | $this->repositoryLead = $repositoryLead; |
|
| 28 | } |
|
| 29 | ||
| 30 | public function validate($value, Constraint $constraint) |
|
| 31 | { |
|
| 32 | if (!$constraint instanceof LeadExist) { |
|
| 33 | throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\LeadExist'); |
|
| 34 | } |
|
| 35 | ||
| 36 | /** @var Lead $lead */ |
|
| 37 | $lead = $this->context->getRoot()->getData(); |
|
| 38 | if ($this->repositoryLead->leadExist($lead->getOrigin(), $lead->getExternalReference())) { |
|
| 39 | $this->context->buildViolation($constraint->message) |
|
| 40 | ->setParameter('{{ origin }}', $lead->getOrigin()) |
|
| 41 | ->setParameter('{{ external_reference }}', $lead->getExternalReference()) |
|
| 42 | ->addViolation(); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||
| @@ 14-44 (lines=31) @@ | ||
| 11 | /** |
|
| 12 | * @Annotation |
|
| 13 | */ |
|
| 14 | class LeadNotExistValidator extends ConstraintValidator |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * @var LeadRepository |
|
| 18 | */ |
|
| 19 | protected $repositoryLead; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * NotCreatedSameLeadValidator constructor. |
|
| 23 | * @param LeadRepository $repositoryLead |
|
| 24 | */ |
|
| 25 | public function __construct(LeadRepository $repositoryLead) |
|
| 26 | { |
|
| 27 | $this->repositoryLead = $repositoryLead; |
|
| 28 | } |
|
| 29 | ||
| 30 | public function validate($value, Constraint $constraint) |
|
| 31 | { |
|
| 32 | if (!$constraint instanceof LeadNotExist) { |
|
| 33 | throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\LeadNotExist'); |
|
| 34 | } |
|
| 35 | /** @var Lead $lead */ |
|
| 36 | $lead = $this->context->getRoot()->getData(); |
|
| 37 | if (!$this->repositoryLead->leadExist($lead->getOrigin(), $lead->getExternalReference())) { |
|
| 38 | $this->context->buildViolation($constraint->message) |
|
| 39 | ->setParameter('{{ origin }}', $lead->getOrigin()) |
|
| 40 | ->setParameter('{{ external_reference }}', $lead->getExternalReference()) |
|
| 41 | ->addViolation(); |
|
| 42 | } |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||