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")); } } }
/** * {@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]); } }
public function verifyDeliveryModule($value, ExecutionContextInterface $context) { $module = ModuleQuery::create()->filterActivatedByTypeAndId(BaseModule::DELIVERY_MODULE_TYPE, $value)->findOne(); if (null === $module) { $context->addViolation(Translator::getInstance()->trans("Delivery module ID not found")); } elseif (!$module->isDeliveryModule()) { $context->addViolation(sprintf(Translator::getInstance()->trans("delivery module %s is not a Thelia\\Module\\DeliveryModuleInterface"), $module->getCode())); } }
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")); } if ($data["password"] !== '' && strlen($data["password"]) < 4) { $context->addViolation(Translator::getInstance()->trans("password must be composed of at least 4 characters")); } }
public function checkStateId($value, ExecutionContextInterface $context) { if ($value['migrate']) { if (null !== ($state = StateQuery::create()->findPk($value['new_state']))) { if ($state->getCountryId() !== $value['new_country']) { $context->addViolation(Translator::getInstance()->trans("The state id '%id' does not belong to country id '%id_country'", ['%id' => $value['new_state'], '%id_country' => $value['new_country']])); } } else { $context->addViolation(Translator::getInstance()->trans("The state id '%id' doesn't exist", ['%id' => $value['new_state']])); } } }
public function verifyPasswordField($value, ExecutionContextInterface $context) { $data = $context->getRoot()->getData(); if ($data["password"] === '' && $data["password_confirm"] === '') { $context->addViolation("password can't be empty"); } if ($data["password"] != $data["password_confirm"]) { $context->addViolation("password confirmation is not the same as password field"); } $minLength = ConfigQuery::getMinimuAdminPasswordLength(); if (strlen($data["password"]) < $minLength) { $context->addViolation("password must be composed of at least {$minLength} characters"); } }
public function verifyState($value, ExecutionContextInterface $context) { $data = $context->getRoot()->getData(); if (null !== ($country = CountryQuery::create()->findPk($data['country']))) { if ($country->getHasStates()) { if (null !== ($state = StateQuery::create()->findPk($data['state']))) { if ($state->getCountryId() !== $country->getId()) { $context->addViolation(Translator::getInstance()->trans("This state doesn't belong to this country.")); } } else { $context->addViolation(Translator::getInstance()->trans("You should select a state for this country.")); } } } }
/** * 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 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 verifyCountry($value, ExecutionContextInterface $context) { $address = CountryQuery::create()->findPk($value); if (null === $address) { $context->addViolation(Translator::getInstance()->trans("Country ID not found")); } }
public function verifyExistingEmail($value, ExecutionContextInterface $context) { $customer = NewsletterQuery::create()->filterByUnsubscribed(false)->findOneByEmail($value); if ($customer) { $context->addViolation(Translator::getInstance()->trans("You are already registered!")); } }
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 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 verifyExistingEmail($value, ExecutionContextInterface $context) { $customer = CustomerQuery::getCustomerByEmail($value); if ($customer) { $context->addViolation(Translator::getInstance()->trans("This email already 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")); } }
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 verifyTaxRuleId($value, ExecutionContextInterface $context) { $taxRule = TaxRuleQuery::create()->findPk($value); if (null === $taxRule) { $context->addViolation(Translator::getInstance()->trans("Tax rule ID not found")); } }
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 verifyTaxId($value, ExecutionContextInterface $context) { $tax = TaxQuery::create()->findPk($value); if (null === $tax) { $context->addViolation("Tax ID not found"); } }
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 verifyCode($value, ExecutionContextInterface $context) { /* check unicity */ $profile = ProfileQuery::create()->findOneByCode($value); if (null !== $profile) { $context->addViolation(Translator::getInstance()->trans("Profile `code` already exists")); } }
/** * 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); } }
/** * @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.")); } }
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); }
function it_does_not_add_violation(ExecutionContextInterface $context, PromotionCouponGeneratorInstructionInterface $instruction, GenerationPolicyInterface $generationPolicy) { $constraint = new CouponPossibleGenerationAmount(); $instruction->getAmount()->willReturn(5); $instruction->getCodeLength()->willReturn(1); $generationPolicy->isGenerationPossible($instruction)->willReturn(true); $generationPolicy->getPossibleGenerationAmount($instruction)->shouldNotBeCalled(); $context->addViolation($constraint->message, Argument::any())->shouldNotBeCalled(); $this->validate($instruction, $constraint); }
public function checkIsRequiredCode($value, ExecutionContextInterface $context) { if ($this->form->has('id')) { if (null !== ($orderStatus = OrderStatusQuery::create()->findOneById($this->form->get('id')->getData()))) { if (!$orderStatus->getProtectedStatus() && empty($this->form->get('code')->getData())) { $context->addViolation(Translator::getInstance()->trans("This value should not be blank.")); } } } }
/** * If the user select "I'am a new customer", we make sure is email address does not exit in the database. */ public function verifyExistingEmail($value, ExecutionContextInterface $context) { $data = $context->getRoot()->getData(); if ($data["account"] == 0) { $customer = CustomerQuery::create()->findOneByEmail($value); if ($customer) { $context->addViolation(Translator::getInstance()->trans("A user already exists with this email address. Please login or if you've forgotten your password, go to Reset Your Password.")); } } }
function it_adds_violation_if_variant_with_given_same_options_already_exists(ExecutionContextInterface $context, ProductInterface $product, ProductVariantInterface $variant, ProductVariantsParityCheckerInterface $variantsParityChecker) { $constraint = new ProductVariantCombination(['message' => 'Variant with given options already exists']); $variant->getProduct()->willReturn($product); $product->hasVariants()->willReturn(true); $product->hasOptions()->willReturn(true); $variantsParityChecker->checkParity($variant, $product)->willReturn(true); $context->addViolation('Variant with given options already exists', Argument::any())->shouldBeCalled(); $this->validate($variant, $constraint); }