/**
  * @param ExecutionContextInterface $context
  */
 public function isValidUppMsgType(ExecutionContextInterface $context)
 {
     $uppMsgType = $this->getUppMsgType();
     if (self::MSGTYPE_GET !== $uppMsgType) {
         $context->addViolationAt('status', "Invalid uppMsgType '{$uppMsgType}' given!");
     }
 }
Пример #2
0
 /**
  * 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.');
         }
     }
 }
Пример #3
0
 /**
  * @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())));
     }
 }
 /**
  * Validates contact method
  *
  * @param ContactRequest            $object
  * @param ExecutionContextInterface $context
  */
 public static function validate(ContactRequest $object, ExecutionContextInterface $context)
 {
     $emailError = $phoneError = false;
     switch ($object->getPreferredContactMethod()) {
         case ContactRequest::CONTACT_METHOD_PHONE:
             $phoneError = !$object->getPhone();
             break;
         case ContactRequest::CONTACT_METHOD_EMAIL:
             $emailError = !$object->getEmailAddress();
             break;
         case ContactRequest::CONTACT_METHOD_BOTH:
         default:
             $phoneError = !$object->getPhone();
             $emailError = !$object->getEmailAddress();
     }
     if ($emailError) {
         $context->addViolationAt('emailAddress', 'This value should not be blank.');
     }
     if ($phoneError) {
         $context->addViolationAt('phone', 'This value should not be blank.');
     }
 }
Пример #5
0
 /**
  * @param string|array $message
  * @param array        $parameters
  * @param null         $value
  *
  * @return ErrorElement
  */
 public function addViolation($message, $parameters = array(), $value = null)
 {
     if (is_array($message)) {
         $value = isset($message[2]) ? $message[2] : $value;
         $parameters = isset($message[1]) ? (array) $message[1] : array();
         $message = isset($message[0]) ? $message[0] : 'error';
     }
     $subPath = (string) $this->getCurrentPropertyPath();
     if ($this->context instanceof LegacyExecutionContextInterface) {
         $this->context->addViolationAt($subPath, $message, $parameters, $value);
     } else {
         $this->context->buildViolation($message)->atPath($subPath)->setParameters($parameters)->setInvalidValue($value)->addViolation();
     }
     $this->errors[] = array($message, $parameters, $value);
     return $this;
 }
Пример #6
0
 /**
  * Si es un user nuevo el password debe ser obligatorio.
  *
  * @param ExecutionContextInterface $ec Contexto de Ejecuci..n.
  *
  * @return void
  */
 public function validatePassword(ExecutionContextInterface $ec)
 {
     $plainPassword = $this->getPlainPassword();
     if (!$this->id && empty($plainPassword)) {
         $ec->addViolationAt('plainPassword', 'La contraseña no debe estar vacía.');
     }
 }
Пример #7
0
 /**
  * @param ExecutionContextInterface $context
  */
 public function validateEntity(ExecutionContextInterface $context)
 {
     if ($this->getType() == self::TYPE_PAGE_LINK && !$this->getNodeTranslation()) {
         $context->addViolationAt('nodeTranslation', 'Please select a page');
     } elseif ($this->getType() == self::TYPE_URL_LINK) {
         if (strlen($this->getTitle()) == 0) {
             $context->addViolationAt('title', 'Please set the link title');
         }
         if (strlen($this->getUrl()) == 0) {
             $context->addViolationAt('url', 'Please set the link URL');
         }
     }
 }
 /**
  * @param ExecutionContextInterface $context
  */
 public function isValidReqType(ExecutionContextInterface $context)
 {
     $reqType = $this->getReqType();
     if (!in_array($reqType, array_keys(\Dominikzogg\ClassHelpers\getConstantsWithPrefix(__CLASS__, 'REQTYPE_')))) {
         $context->addViolationAt('status', "Unknown reqType '{$reqType}' given!");
     }
 }
Пример #9
0
 /**
  * @Assert\Callback
  */
 public function isDataFieldValid(ExecutionContextInterface $context)
 {
     //TODO: why is it not working?
     $context->addViolationAt('textValue', 'Haaaaha', array(), null);
 }
Пример #10
0
 /**
  * @Assert\Callback
  */
 public function forbiddenWords(ExecutionContextInterface $context)
 {
     $forbiddenWords = array('branches', 'details', 'activity', 'default');
     if (in_array($this->branchId, $forbiddenWords)) {
         $context->addViolationAt('branchId', 'Branch ID is a forbidden word ("' . $this->branchId . '") !', array(), null);
     }
 }
Пример #11
0
 /**
  * @Assert\Callback
  * Need to change this to avoid team name duplicates
  */
 public function forbiddenWords(ExecutionContextInterface $context)
 {
     $forbiddenWords = array('test');
     if (in_array($this->usernameCanonical, $forbiddenWords)) {
         $context->addViolationAt('usernameCanonical', 'Username is a forbidden word ("' . $this->usernameCanonical . '") !', array(), null);
     }
 }
 /**
  * @param ExecutionContextInterface $context
  */
 public function isValidStatus(ExecutionContextInterface $context)
 {
     $status = $this->getStatus();
     if (!in_array($status, array_keys(\Dominikzogg\ClassHelpers\getConstantsWithPrefix(__CLASS__, 'RESPONSESTATUS_')))) {
         $context->addViolationAt('status', "Unknown status '{$status}' given!");
     }
 }
Пример #13
0
 /**
  * @Assert\Callback
  */
 public function contenuValide(ExecutionContextInterface $context)
 {
     $mots_interdits = array('échec', 'abandon');
     // On vérifie que le contenu ne contient pas l'un des mots
     if (preg_match('#' . implode('|', $mots_interdits) . '#', $this->getContenu())) {
         // 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('contenu', 'Contenu invalide car il contient un mot interdit.', array(), null);
     }
 }
 /**
  * @param ExecutionContextInterface $context
  */
 public function isValidExpy(ExecutionContextInterface $context)
 {
     $expy = $this->getExpy();
     $now = new \DateTime();
     $years = array();
     for ($i = 0; $i < 10; $i++) {
         $years[] = $now->format('y');
         $now->modify('+1year');
     }
     if (!in_array($expy, $years, true)) {
         $context->addViolationAt('expy', "Invalid expy '{$expy}' given!");
     }
 }
Пример #15
0
 /**
  * @Assert\Callback(groups={"suscribe"})
  * use Symfony\Component\Validator\Context\ExecutionContextInterface;
  */
 public function validate(ExecutionContextInterface $context)
 {
     $val = $this->getUsername();
     if (!empty($val)) {
         if ($this->getUsername() == $this->getPassword()) {
             $context->addViolationAt('username', 'Votre login ne doit pas être identique à votre mot de passe', array(), null);
         }
     }
     $val = $this->getEmail();
     if (!empty($val)) {
         if ($this->getUsername() == $this->getEmail()) {
             $context->addViolationAt('email', 'Votre email ne doit pas être identique à votre login', array(), null);
         }
     }
 }
Пример #16
0
 /**
  * @param ExecutionContextInterface|LegacyExecutionContextInterface $context
  */
 public function isStatusErroneous($context)
 {
     if ($this->getBinaryContent() && $this->getProviderStatus() == self::STATUS_ERROR) {
         // Interface compatibility, the new ExecutionContextInterface should be typehinted when support for Symfony <2.5 is dropped
         if (!$context instanceof ExecutionContextInterface && !$context instanceof LegacyExecutionContextInterface) {
             throw new \InvalidArgumentException('Argument 1 should be an instance of Symfony\\Component\\Validator\\ExecutionContextInterface or Symfony\\Component\\Validator\\Context\\ExecutionContextInterface');
         }
         if ($context instanceof LegacyExecutionContextInterface) {
             $context->addViolationAt('binaryContent', 'invalid', array(), null);
         } else {
             $context->buildViolation('invalid')->atPath('binaryContent')->addViolation();
         }
     }
 }
Пример #17
0
 public function isRegionValid(ExecutionContextInterface $context)
 {
     if ($this->getCountry() && $this->getCountry()->hasRegions() && !$this->region && !$this->regionText) {
         // do not allow saving text region in case when region was checked from list
         // except when in base data region text existed
         // another way region_text field will be null, logic are placed in form listener
         $propertyPath = $context->getPropertyPath() . '.region';
         $context->addViolationAt($propertyPath, 'State is required for country {{ country }}', ['{{ country }}' => $this->getCountry()->getName()]);
     }
 }
Пример #18
0
 /**
  * @Assert\Callback(groups={"Adding","Editing"})
  */
 public function validateGroup(ExecutionContextInterface $context)
 {
     if ($this->isSuperAdmin() && $this->getGroup() !== null) {
         $context->addViolationAt('group', 'user_admin.assert.group.super_admin');
     } elseif (!$this->isSuperAdmin() && $this->getGroup() === null) {
         $context->addViolationAt('group', 'user_admin.assert.group.empty');
     }
 }
Пример #19
0
 /**
  * @Assert\Callback
  */
 public function filenamesUnique(ExecutionContextInterface $context)
 {
     $filenames = array();
     foreach ($this->files as $key => $file) {
         $filenames[$key] = $file->getFilename();
     }
     if (count($filenames) !== count(array_unique($filenames))) {
         $context->addViolationAt('files', 'Duplicated filenames !', array(), null);
     }
 }
Пример #20
0
 /**
  * Custom validation constraint
  * Not valid if no one recipient specified
  *
  * @param ExecutionContextInterface $context
  */
 public function isValid(ExecutionContextInterface $context)
 {
     $notValid = $this->getGroups()->isEmpty() && $this->getUsers()->isEmpty() && $this->getEmail() == null && $this->getOwner() == null;
     if ($notValid) {
         $propertyPath = $context->getPropertyPath() . '.recipientList';
         $context->addViolationAt($propertyPath, 'oro.notification.validators.recipient_list.empty.message');
     }
 }
Пример #21
0
 /**
  * @Assert\Callback
  */
 public function packageNamesUnique(ExecutionContextInterface $context)
 {
     $packageNames = array();
     foreach ($this->packages as $key => $package) {
         $packageNames[$key] = $package->getName();
     }
     if (count($packageNames) !== count(array_unique($packageNames))) {
         $context->addViolationAt('packages', 'Duplicated package names !', array(), null);
     }
 }
Пример #22
0
 /**
  * @Assert\Callback
  */
 public function forbiddenWords(ExecutionContextInterface $context)
 {
     $forbiddenWords = array('metas', 'profile', 'activity');
     if (in_array($this->metaId, $forbiddenWords)) {
         $context->addViolationAt('metaId', 'meta ID is a forbidden word ("' . $this->metaId . '") !', array(), null);
     }
 }