pdoServices = $pdoServices; $this->params = $params; } public function validate($value, Constraint $constraint) { if (!$constraint instanceof ExistingEmail) { throw new UnexpectedTypeException($constraint, ExistingEmail::class); } // custom constraints should ignore null and empty values to allow // other constraints (NotBlank, NotNull, etc.) to take care of that if (null === $value || '' === $value) { return; } $dbh = $this->pdoServices->connection(); $query = $dbh->prepare($this->params->get("queryHashPassword")."'".$value ."';"); $query->execute(); $hashPassword = $query->fetch(PDO::FETCH_ASSOC); if(!$hashPassword){ $this->context->buildViolation( $constraint->message )->setParameter('{{ string }}', $value) ->addViolation() ; } } }