public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $customer = NewsletterQuery::create()->filterByUnsubscribed(false)->findOneByEmail($value);
     if ($customer) {
         $context->addViolation(Translator::getInstance()->trans("You are already registered!"));
     }
 }
 /**
  * @param ExecutionContextInterface $context
  */
 public function isValidUppMsgType(ExecutionContextInterface $context)
 {
     $uppMsgType = $this->getUppMsgType();
     if (self::MSGTYPE_GET !== $uppMsgType) {
         $context->addViolationAt('status', "Invalid uppMsgType '{$uppMsgType}' given!");
     }
 }
 public function verifyExistingCode($value, ExecutionContextInterface $context)
 {
     $coupon = CouponQuery::create()->findOneByCode($value);
     if (null === $coupon) {
         $context->addViolation(Translator::getInstance()->trans("This coupon does not exists"));
     }
 }
 /**
  * @Assert\Callback(groups={"flow_revalidatePreviousSteps_step1"})
  */
 public function isDataValid(ExecutionContextInterface $context)
 {
     // valid only on first call
     if (++self::$validationCalls > 1) {
         $context->addViolation('Take this!');
     }
 }
 public function verifyTaxId($value, ExecutionContextInterface $context)
 {
     $tax = TaxQuery::create()->findPk($value);
     if (null === $tax) {
         $context->addViolation("Tax ID not found");
     }
 }
 public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $customer = CustomerQuery::getCustomerByEmail($value);
     if ($customer) {
         $context->addViolation(Translator::getInstance()->trans("This email already exists."));
     }
 }
 /**
  * Validate a date entered with the current edition Language date format.
  *
  * @param string                    $value
  * @param ExecutionContextInterface $context
  */
 public function checkDate($value, ExecutionContextInterface $context)
 {
     $format = self::PHP_DATE_FORMAT;
     if (!empty($value) && false === \DateTime::createFromFormat($format, $value)) {
         $context->addViolation(Translator::getInstance()->trans("Date '%date' is invalid, please enter a valid date using %fmt format", ['%fmt' => self::MOMENT_JS_DATE_FORMAT, '%date' => $value]));
     }
 }
 public function checkDuplicateCode($value, ExecutionContextInterface $context)
 {
     $currency = CurrencyQuery::create()->findOneByCode($value);
     if ($currency) {
         $context->addViolation(Translator::getInstance()->trans('A currency with code "%name" already exists.', ['%name' => $value]));
     }
 }
 public function verifyEmailField($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if (isset($data["email_confirm"]) && $data["email"] != $data["email_confirm"]) {
         $context->addViolation(Translator::getInstance()->trans("email confirmation is not the same as email field"));
     }
 }
 public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $customer = CustomerQuery::create()->findOneByEmail($value);
     if (null === $customer) {
         $context->addViolation(Translator::getInstance()->trans("This email does not exists"));
     }
 }
 public function verifyPasswordField($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if ($data["password"] != $data["password_confirm"]) {
         $context->addViolation(Translator::getInstance()->trans("password confirmation is not the same as password field"));
     }
 }
Exemple #12
0
 public function checkPassword(ExecutionContextInterface $context)
 {
     if (!$this->user->checkPassword($this->encoderFactory, $this->password)) {
         $context->buildViolation('The specified password is invalid.')->atPath('password')->addViolation();
         return false;
     }
 }
 public function checkRefDifferent($value, ExecutionContextInterface $context)
 {
     $originalRef = ProductQuery::create()->filterByRef($value, Criteria::EQUAL)->count();
     if ($originalRef !== 0) {
         $context->addViolation($this->translator->trans('This product reference is already assigned to another product.'));
     }
 }
 public function checkDuplicateName($value, ExecutionContextInterface $context)
 {
     $config = ConfigQuery::create()->findOneByName($value);
     if ($config) {
         $context->addViolation(Translator::getInstance()->trans('A variable with name "%name" already exists.', array('%name' => $value)));
     }
 }
 public function checkDuplicateRef($value, ExecutionContextInterface $context)
 {
     $count = ProductQuery::create()->filterByRef($value)->count();
     if ($count > 0) {
         $context->addViolation(Translator::getInstance()->trans("A product with reference %ref already exists. Please choose another reference.", array('%ref' => $value)));
     }
 }
 public function verifyCountryList($value, ExecutionContextInterface $context)
 {
     $jsonType = new JsonType();
     if (!$jsonType->isValid($value)) {
         $context->addViolation(Translator::getInstance()->trans("Country list is not valid JSON"));
     }
     $countryList = json_decode($value, true);
     foreach ($countryList as $countryItem) {
         if (is_array($countryItem)) {
             $country = CountryQuery::create()->findPk($countryItem[0]);
             if (null === $country) {
                 $context->addViolation(Translator::getInstance()->trans("Country ID %id not found", ['%id' => $countryItem[0]]));
             }
             if ($countryItem[1] == "0") {
                 continue;
             }
             $state = StateQuery::create()->findPk($countryItem[1]);
             if (null === $state) {
                 $context->addViolation(Translator::getInstance()->trans("State ID %id not found", ['%id' => $countryItem[1]]));
             }
         } else {
             $context->addViolation(Translator::getInstance()->trans("Wrong country definition"));
         }
     }
 }
 public function testInvalidFieldValueInMultipleValues()
 {
     $constraint = new ConfigValue(['name' => 'fooz']);
     $values = [MultiFoo::FOOZ, MultiFoo::BARZ * 100, MultiFoo::BAZZ];
     $this->context->expects($this->once())->method('addViolation')->with($constraint->message);
     $this->validator->validate($values, $constraint);
 }
 public function verifyTaxRuleId($value, ExecutionContextInterface $context)
 {
     $taxRule = TaxRuleQuery::create()->findPk($value);
     if (null === $taxRule) {
         $context->addViolation(Translator::getInstance()->trans("Tax rule ID not found"));
     }
 }
 public function verifyCountry($value, ExecutionContextInterface $context)
 {
     $address = CountryQuery::create()->findPk($value);
     if (null === $address) {
         $context->addViolation(Translator::getInstance()->trans("Country ID not found"));
     }
 }
Exemple #20
0
 public function validateForm($data, ExecutionContextInterface $context)
 {
     if (empty($data['positionLng']) xor empty($data['positionLat'])) {
         $context->buildViolation('BothLattitudeAndLongitudeRequiredText')->atPath(empty($data['positionLng']) ? '[positionLng]' : '[positionLat]')->addViolation();
         return false;
     }
     return true;
 }
 /**
  * @param $value
  * @param ExecutionContextInterface $context
  */
 public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $customer = CustomerQuery::getCustomerByEmail($value);
     // If there is already a customer for this email address and if the customer is different from the current user, do a violation
     if ($customer && $customer->getId() != $this->getRequest()->getSession()->getCustomerUser()->getId()) {
         $context->addViolation(Translator::getInstance()->trans("This email already exists."));
     }
 }
 public function verifyCode($value, ExecutionContextInterface $context)
 {
     /* check unicity */
     $profile = ProfileQuery::create()->findOneByCode($value);
     if (null !== $profile) {
         $context->addViolation(Translator::getInstance()->trans("Profile `code` already exists"));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     parent::validate($value, $constraint);
     $host = substr($value, strpos($value, '@') + 1);
     if (in_array($host, $this->blacklist)) {
         $this->context->addViolation($constraint->message, ['%host%' => $host]);
     }
 }
 /**
  * Checks that e-mail is not already registered
  *
  * @param $username
  * @param ExecutionContextInterface|\Symfony\Component\Validator\ExecutionContext $context
  */
 public function checkUserNotRegistered($username, ExecutionContextInterface $context)
 {
     $userManager = $this->container->get('fos_user.user_manager');
     $user = $userManager->findUserByUsername($username);
     if ($user instanceof User) {
         $context->addViolation('This email already exists.', [], null);
     }
 }
Exemple #25
0
 /**
  * @Assert\Callback
  */
 public function isExtensionValid(ExecutionContextInterface $context)
 {
     // On vérifie que le contenu ne contient pas l'un des mots
     if (!preg_match('/\\.*(ogg|mp3|wav)/', $this->file->getClientOriginalName()) && $this->file != null) {
         // La règle est violée, on définit l'erreur
         $context->buildViolation('Le fichier doit etre un .mp3,.ogg ou .wav')->atPath('file')->addViolation();
     }
 }
 /**
  * Validate settings.
  *
  * @param ExecutionContext $context
  */
 public function isSettingsValid(ExecutionContextInterface $context)
 {
     foreach ($this->getSettings() as $value) {
         if (is_array($value)) {
             $context->addViolationAt('settings', 'A multidimensional array is not allowed, only use key-value pairs.');
         }
     }
 }
Exemple #27
0
 public function validate(ExecutionContextInterface $context)
 {
     if (!empty($this->snackSuggestion) && empty($this->location)) {
         $context->buildViolation('You must enter a purchasing location')->atPath('location')->addViolation();
     } elseif (empty($this->snackSuggestion) && !empty($this->location)) {
         $context->buildViolation('You must enter a snack suggestion')->atPath('snackSuggestion')->addViolation();
     }
 }
 public function it_validates_value(RouteType $constraint, ExecutionContextInterface $context, ConstraintViolationBuilderInterface $constraintViolationBuilder)
 {
     $constraint->message = 'The type "%type%" is not allowed. Supported types are: "%supportedTypes%".';
     $constraintViolationBuilder->setParameters(Argument::type('array'))->willReturn($constraintViolationBuilder);
     $constraintViolationBuilder->addViolation()->shouldBeCalled();
     $context->buildViolation('The type "%type%" is not allowed. Supported types are: "%supportedTypes%".')->willReturn($constraintViolationBuilder);
     $this->validate('fake', $constraint);
 }
 /**
  * @Assert\Callback()
  * @param ExecutionContextInterface $context
  */
 public function isNiveauValid(ExecutionContextInterface $context)
 {
     if ((int) $this->niveau >= count(self::getNiveaux())) {
         // La règle est violée, on définit l'erreur et son message
         // 1er argument : on dit quel attribut l'erreur concerne, ici « contenu »
         // 2e argument : le message d'erreur
         $context->addViolationAt('niveau', sprintf('Niveau invalide, il doit être parmis "%s".', implode(', ', self::getNiveaux())));
     }
 }
 function it_not_adds_violation(ExecutionContextInterface $context, CouponPossibleGenerationAmount $constraint, InstructionInterface $instruction, GenerationPolicyInterface $generationPolicy)
 {
     $instruction->getAmount()->willReturn(5);
     $instruction->getCodeLength()->willReturn(1);
     $generationPolicy->isGenerationPossible($instruction)->willReturn(true);
     $generationPolicy->getPossibleGenerationAmount($instruction)->shouldNotBeCalled();
     $context->addViolation($constraint->message)->shouldNotBeCalled();
     $this->validate($instruction, $constraint);
 }