Пример #1
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();
     }
 }
Пример #2
0
 /**
  * @Assert\Callback()
  * @param ExecutionContextInterface $context
  */
 public function isValid(ExecutionContextInterface $context)
 {
     if (!$this->CampaignId && !$this->AdGroupId && !$this->KeywordId) {
         $context->buildViolation('Должно быть указано одно из следующих значений: CampaignId, AdGroupId, KeywordId')->atPath('CampaignId')->atPath('AdGroupId')->atPath('KeywordId')->addViolation();
     }
     if (!$this->Bid && !$this->ContextBid && !$this->StrategyPriority) {
         $context->buildViolation('Должно быть указано одно из следующих значений: Bid, ContextBid, StrategyPriority')->atPath('Bid')->atPath('ContextBid')->atPath('StrategyPriority')->addViolation();
     }
 }
 /**
  * @param ExecutionContextInterface $context
  */
 public function isValid(ExecutionContextInterface $context)
 {
     if (!($this->Ids == [] && count($this->CampaignIds) > 0)) {
         $context->buildViolation('CampaignIds должны быть указаны, если Ids пусты')->atPath('CampaignIds')->addViolation();
     }
     if (!($this->CampaignIds == [] && count($this->Ids) > 0)) {
         $context->buildViolation('Ids должны быть указаны, если CampaignIds пусты')->atPath('Ids')->addViolation();
     }
 }
Пример #4
0
 /**
  * @param ExecutionContextInterface $context
  */
 public function isValid(ExecutionContextInterface $context)
 {
     if (!$this->CampaignId and !$this->AdGroupId and !$this->Id) {
         $context->buildViolation('Необходимо указать CampaignId либо AdGroupId либо Id')->atPath('CampaignId')->atPath('AdGroupId')->atPath('Id')->addViolation();
     }
     if (!$this->Bid and !$this->StrategyPriority) {
         $context->buildViolation('Необходимо указать Bid либо StrategyPriority')->atPath('Bid')->atPath('StrategyPriority')->addViolation();
     }
 }
Пример #5
0
 public function fechaMayor(ExecutionContextInterface $context)
 {
     if ($this->getFechanacimiento() > new \DateTime('today')) {
         $context->buildViolation('No puede haber nacido en el futuro.')->atPath('fechanacimiento')->addViolation();
     }
     if ($this->getFechanacimiento()->diff(new \DateTime('today'))->y < 18) {
         $context->buildViolation('Debe ser mayor de 18 años.')->atPath('fechanacimiento')->addViolation();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint) {
   // '0' is invalid, since elsewhere we check it using empty().
   /** @var \Drupal\crop\Entity\CropType $value */
   if (trim($value->id()) == '0') {
     $this->context->buildViolation($constraint->message)
       ->atPath('id')
       ->addViolation();
   }
 }
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint) {
   /** @var \Drupal\crop\Entity\CropType $value */
   $aspect_ratio = $value->getAspectRatio();
   if (!empty($aspect_ratio) && !preg_match($value::VALIDATION_REGEXP, $aspect_ratio)) {
     $this->context->buildViolation($constraint->message)
       ->atPath('aspect_ratio')
       ->addViolation();
   }
 }
 /**
  * @Assert\Callback()
  * @param ExecutionContextInterface $context
  */
 public function isValid(ExecutionContextInterface $context)
 {
     if ($this->SuspendOnHolidays == new YesNoEnum(YesNoEnum::NO) && $this->StartHour === null) {
         $context->buildViolation('При SuspendOnHolidays=NO должен быть указан параметр StartHour')->atPath('StartHour')->addViolation();
     }
     if ($this->SuspendOnHolidays == new YesNoEnum(YesNoEnum::NO) && $this->EndHour === null) {
         $context->buildViolation('При SuspendOnHolidays=NO должен быть указан параметр EndHour')->atPath('EndHour')->addViolation();
     }
 }
 /**
  * @Assert\Callback()
  * @param ExecutionContextInterface $context
  */
 public function isValid(ExecutionContextInterface $context)
 {
     if (!$this->CampaignId && !$this->AdGroupId) {
         $context->buildViolation('Должно быть указано одно из следующих значений: CampaignId, AdGroupId')->atPath('CampaignId')->atPath('AdGroupId')->addViolation();
     }
     if (!$this->MobileAdjustment && !$this->DemographicsAdjustments && !$this->RetargetingAdjustments) {
         $context->buildViolation('Должно быть указано одно из следующих значений: MobileAdjustment, DemographicsAdjustments, RetargetingAdjustments')->atPath('MobileAdjustment')->atPath('DemographicsAdjustments')->atPath('RetargetingAdjustments')->addViolation();
     }
 }
Пример #10
0
 /**
  * @Assert\Callback()
  * @param ExecutionContextInterface $context
  */
 public function isValid(ExecutionContextInterface $context)
 {
     if (!$this->Href && !$this->VCardId) {
         $context->buildViolation('Необходимо указать Href или VCardId')->atPath('Href')->atPath('VCardId')->addViolation();
     }
     if (!$this->Href && $this->SitelinkSetId) {
         $context->buildViolation('Нельзя указать SitelinkSetId при пустом Href')->atPath('SitelinkSetId')->addViolation();
     }
 }
Пример #11
0
 public function validate(ExecutionContextInterface $context)
 {
     if (empty($this->authorEmail) && empty($this->authorPhone)) {
         $context->buildViolation('Please specify either e-mail or phone number.')->atPath('authorEmail')->addViolation();
         $context->buildViolation('Please specify either e-mail or phone number.')->atPath('authorPhone')->addViolation();
         return false;
     }
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function validate($entity, Constraint $constraint)
 {
     // Workflow field name on comment has special requirements.
     $field_storage = $entity->getFieldDefinition()->getFieldStorageDefinition();
     if ($field_storage->getTargetEntityTypeId() == 'comment') {
         if (!$this->isValidFieldname($field_storage, $entity->getEntity())) {
             $this->context->buildViolation($constraint->messageFieldname)->atPath('fieldnameOnComment')->addViolation();
         }
     }
 }
Пример #13
0
 public function fechaMayor(ExecutionContextInterface $context)
 {
     if ($this->getIdpaciente()) {
         if ($this->getFechadiagnostico() < $this->getIdpaciente()->getFechanacimiento()) {
             $context->buildViolation(sprintf('Esta fecha no puede ser menor que la fecha de nacimiento del paciente. (%s)', $this->getIdpaciente()->getFechanacimiento()->format('Y-m-d')))->atPath('fechadiagnostico')->addViolation();
         }
     }
     if ($this->getFechadiagnostico() > new \DateTime('today')) {
         $context->buildViolation('Esta fecha no puede ser mayor que la fecha de hoy.')->atPath('fechadiagnostico')->addViolation();
     }
 }
 public function validate(ExecutionContextInterface $context)
 {
     if ($this->password != $this->repeatPassword) {
         $context->buildViolation('The specified passwords are not identical!')->atPath('password')->addViolation();
         return false;
     }
     if (!PasswordBuilder::isPasswordStrongEnough($this->password)) {
         $context->buildViolation('The password must contain lowercase, uppercase letters and numbers.')->atPath('password')->addViolation();
         return false;
     }
 }
Пример #15
0
 public function validate($data, ExecutionContextInterface $context)
 {
     if (isset($data['consulta_dpi_nombre_apellidos']) && isset($data['consulta_fecha_ingreso']) && isset($data['consulta_procedimiento_realizado'])) {
         $context->buildViolation('Debe seleccionar sólo un método de consulta')->addViolation();
         return;
     }
     if (!isset($data['consulta_dpi_nombre_apellidos']) && !isset($data['consulta_fecha_ingreso']) && !isset($data['consulta_procedimiento_realizado'])) {
         $context->buildViolation('Debe seleccionar al menos un método de consulta')->addViolation();
         return;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate($entity, Constraint $constraint)
 {
     if ($entity->name->value === 'test' && $entity->type->value === 'test2') {
         $this->context->buildViolation($constraint->message)->atPath('type')->addViolation();
     }
     if ($entity->name->value === 'failure-field-name') {
         $this->context->buildViolation('Name field violation')->atPath('name')->addViolation();
     } elseif ($entity->name->value === 'failure-field-type') {
         $this->context->buildViolation('Type field violation')->atPath('type')->addViolation();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     /** @var EntregaNotOverlayDates $constraint */
     /** @var Entrega $value */
     $class = ClassUtils::getClass($this->context->getObject());
     $qb = $this->manager->getRepository($class)->createQueryBuilder('a');
     $qb->andWhere('a.contrato = :contrato')->andWhere(':inico < a.fechaCierre')->andWhere(':cierre > a.fechaInicio')->setParameter('contrato', $value->getContrato())->setParameter('inico', $value->getFechaInicio())->setParameter('cierre', $value->getFechaCierre());
     if ($value->getId()) {
         $qb->andWhere('a.id != :id')->setParameter('id', $value->getId());
     }
     $results = $qb->getQuery()->execute();
     if (count($results) > 0) {
         $this->context->buildViolation($constraint->message)->addViolation();
     }
 }
Пример #18
0
 public function validateForm($data, ExecutionContextInterface $context)
 {
     if ($data['ewcType'] == 'full') {
         if ($data['routeLength'] < 30) {
             $violation = $context->buildViolation('For full areas, the route length cannot be lower than 30 kilometers.')->atPath('[routeLength]')->addViolation();
             return false;
         } else {
             if ($data['routeLength'] >= 30 && $data['routeLength'] < 40 && $data['routeAscent'] < 500) {
                 $context->buildViolation('The route ascent must be greater than 500 meters, if the length is between 30 and 40 kilometers.')->atPath('[routeAscent]')->addViolation();
                 return false;
             }
         }
     }
     return true;
 }
Пример #19
0
 /**
  * @Assert\Callback()
  * @param ExecutionContextInterface $context
  */
 public function isValid(ExecutionContextInterface $context)
 {
     if (stripos($this->Title, '#') !== false) {
         if (mb_strlen($this->Title) > 35) {
             $context->buildViolation('Заголовок объявления слишком велик')->atPath('Title')->addViolation();
         }
     } else {
         if (mb_strlen($this->Title) > 33) {
             $context->buildViolation('Заголовок объявления слишком велик')->atPath('Title')->addViolation();
         }
     }
     if (!$this->Href && $this->SitelinkSetId) {
         $context->buildViolation('Нельзя указать SitelinkSetId при пустом Href')->atPath('SitelinkSetId')->addViolation();
     }
 }
Пример #20
0
 /**
  *@Assert\Callback
  */
 public function validate(ExecutionContextInterface $context)
 {
     if ($this->getProduct() === null) {
         $context->buildViolation('Select a product')->atPath('product')->addViolation();
         return;
     }
     if ($this->getOperation() instanceof Sale && $this->getProduct()->getQty() <= 0) {
         $context->buildViolation('Stock is empty')->atPath('qty')->addViolation();
         return;
     }
     //fixme update fails when product qty is 0
     if ($this->getOperation() instanceof Sale && $this->getProduct()->getQty() - $this->getQty() < 0) {
         $context->buildViolation('No enough stock')->atPath('qty')->addViolation();
         return;
     }
 }
 public function validate($value, Constraint $constraint)
 {
     if (!$constraint instanceof PathWell) {
         return;
     }
     if (false === $this->enabled) {
         return;
     }
     $topology = $this->passwordToPathWellTopology($value);
     foreach ($this->topologies->getBlacklist() as $rule) {
         if (preg_match("#^{$rule}\$#", $topology) === 1) {
             $this->context->buildViolation($constraint->message)->setTranslationDomain('validators')->addViolation();
             return;
         }
     }
 }
Пример #22
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 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);
 }
Пример #24
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();
     }
 }
Пример #25
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;
 }
Пример #26
0
 /**
  * @param ExecutionContextInterface $executionContext
  * @Assert\Callback()
  */
 public function validate(ExecutionContextInterface $executionContext)
 {
     if (!$this->getFirstName() && !$this->getLastName() && !$this->getEmail()) {
         return;
     }
     if (!$this->getFirstName() || !$this->getLastName() || !$this->getEmail()) {
         $executionContext->buildViolation(sprintf('Object %s is not filled correctly', get_class($this)))->addViolation();
     }
 }
Пример #27
0
 /**
  * @param ExecutionContextInterface $executionContext
  * @Assert\Callback()
  */
 public function validate(ExecutionContextInterface $executionContext)
 {
     if (!$this->getStreet() && !$this->getCity() && !$this->getCountryCode() && !$this->getPostalCode()) {
         return;
     }
     if (!$this->getStreet() || !$this->getCity() || !$this->getCountryCode() || !$this->getPostalCode()) {
         $executionContext->buildViolation(sprintf('Object %s is not filled correctly', get_class($this)))->addViolation();
     }
 }
 /**
  * @Assert\Callback()
  * @param ExecutionContextInterface $context
  */
 public function isValid(ExecutionContextInterface $context)
 {
     if ($this->BiddingStrategyType == MobileAppCampaignSearchStrategyTypeEnum::WB_MAXIMUM_CLICKS && !$this->WbMaximumClicks) {
         $context->buildViolation("Свойство WbMaximumClicks должно быть указано, если BiddingStrategyType=WB_MAXIMUM_CLICKS")->atPath("WbMaximumClicks")->addViolation();
     }
     if ($this->BiddingStrategyType == MobileAppCampaignSearchStrategyTypeEnum::WB_MAXIMUM_APP_INSTALLS && !$this->WbMaximumAppInstalls) {
         $context->buildViolation("Свойство WbMaximumAppInstalls должно быть указано, если BiddingStrategyType=WB_MAXIMUM_APP_INSTALLS")->atPath("WbMaximumAppInstalls")->addViolation();
     }
     if ($this->BiddingStrategyType == MobileAppCampaignSearchStrategyTypeEnum::AVERAGE_CPC && !$this->AverageCpc) {
         $context->buildViolation("Свойство AverageCpc должно быть указано, если BiddingStrategyType=AVERAGE_CPC")->atPath("AverageCpc")->addViolation();
     }
     if ($this->BiddingStrategyType == MobileAppCampaignSearchStrategyTypeEnum::AVERAGE_CPI && !$this->AverageCpi) {
         $context->buildViolation("Свойство AverageCpi должно быть указано, если BiddingStrategyType=AVERAGE_CPI")->atPath("AverageCpi")->addViolation();
     }
     if ($this->BiddingStrategyType == MobileAppCampaignSearchStrategyTypeEnum::WEEKLY_CLICK_PACKAGE && !$this->WeeklyClickPackage) {
         $context->buildViolation("Свойство WeeklyClickPackage должно быть указано, если BiddingStrategyType=WEEKLY_CLICK_PACKAGE")->atPath("WeeklyClickPackage")->addViolation();
     }
 }
 function it_does_not_validate_a_non_existent_channel($channelRepository, Channel $constraint, ExecutionContextInterface $context, ConstraintViolationBuilderInterface $violation)
 {
     $channelRepository->getLabelsIndexedByCode()->willReturn(['mobile' => 'mobile']);
     $context->buildViolation(Argument::cetera())->shouldBeCalled()->willReturn($violation);
     $violation->setParameter(Argument::any(), Argument::any())->shouldBeCalled()->willReturn($violation);
     $violation->setCode(Argument::any())->shouldBeCalled()->willReturn($violation);
     $violation->addViolation()->shouldBeCalled();
     $this->initialize($context);
     $this->validate('Magento', $constraint);
 }
 /**
  * @Assert\Callback()
  * @param ExecutionContextInterface $context
  */
 public function isValid(ExecutionContextInterface $context)
 {
     $length = 0;
     foreach ($this->Sitelinks as $link) {
         $length += mb_strlen($link->Title);
     }
     if ($length > 66) {
         $context->buildViolation("Суммарная длина текстов всех быстрых ссылок в наборе — не более 66 символов")->atPath('Sitelink')->addViolation();
     }
 }