示例#1
0
 /**
  * @Assert\Callback
  */
 public function validate(ExecutionContextInterface $context)
 {
     // Vérifie si le nom est bidon
     if ($this->getDebut() > $this->getFin()) {
         $context->addViolationAt('fin', 'La date de début ne peut être postérieure à la date de fin');
     }
     $datesysteme = new \Datetime();
     if ($this->getFin() < $datesysteme) {
         $context->addViolationAt('fin', 'La date de fin ne peut être antérieure à la date du jour');
     }
 }
 /**
  * Validation function for optional constraints
  *
  * @param RentRecoveryPlusCancellation $cancellation
  * @param ExecutionContextInterface $context
  */
 public function checkEndDate($cancellation, ExecutionContextInterface $context)
 {
     $expiresAt = new \DateTime($cancellation->getPolicyExpiresAt());
     $endAt = new \DateTime($cancellation->getPolicyEndAt());
     $now = new \DateTime();
     $now->setTime(0, 0, 0);
     if ($endAt > $expiresAt) {
         $context->addViolationAt('policyEndAt', 'Requested date exceeds existing end date of ' . $expiresAt->format('d-m-Y'), array(), null);
     } else {
         if ($endAt < $now) {
             $context->addViolationAt('policyEndAt', 'Requested date is in the past', array(), null);
         }
     }
 }
 public function checkAtLeastOnePhoneNumberIsDefined($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if (empty($data["phone"]) && empty($data["cellphone"])) {
         $context->addViolationAt("phone", Translator::getInstance()->trans("Please enter a home or mobile phone number"));
     }
 }
示例#4
0
 public function isSubjectValid(ExecutionContextInterface $context)
 {
     $text = preg_replace(array('/<a[^>]+href[^>]+>/', '/<\\/a>/'), '', $this->subjectParsed);
     if (mb_strlen($text, 'utf-8') > 500) {
         $context->addViolationAt('subject', 'The subject too long');
     }
 }
示例#5
0
 public function isValid(ExecutionContextInterface $context)
 {
     $is_valid = $this->start <= $this->end;
     if (!$is_valid) {
         $context->addViolationAt('end', 'bladetester_calendar.validation.event_dates', array(), null);
     }
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 public function isVoteValid(ExecutionContextInterface $context)
 {
     if (!$this->checkValue($this->value)) {
         $message = 'A vote cannot have a 0 value';
         $propertyPath = $context->getPropertyPath() . '.value';
         $context->addViolationAt($propertyPath, $message);
     }
 }
示例#7
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.');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function addViolation()
 {
     if ($this->propertyPath) {
         $this->context->addViolationAt($this->propertyPath, $this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code);
         return;
     }
     $this->context->addViolation($this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code);
 }
示例#9
0
 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())));
     }
 }
示例#10
0
 public function isCorrectRequiredFields(ExecutionContextInterface $context)
 {
     if ($this->group->getFillFieldsRequired()) {
         $groupFieldsIds = $this->group->getFieldsIds();
         $userFieldsIds = $this->getFieldsIds();
         if (!empty(array_diff($groupFieldsIds, $userFieldsIds))) {
             $context->addViolationAt('fields', 'Please to fill required fields', array(), null);
         }
     }
 }
示例#11
0
文件: Article.php 项目: nassafou/blog
 public function contenuValide(ExecutionContextInterface $context)
 {
     $mots_interdits = array('échec', 'abandon');
     // On verfie que le contenu ne contient pas l'un des mots
     if (preg_match('#' . implode('|', $mots_interdits) . '#', $this->getContenu())) {
         //La regle est violé, on definit le l'erreur et son message
         // 1 er argument : on dit quel attribut l'erreur concerne, ici <<contenu >>
         // 2 e argument : le message d'erreur
         $context->addViolationAt('contenu', 'Contenu invalide car il contient un mot inderdit, array(), null');
     }
 }
 /**
  * @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();
     $this->context->addViolationAt($subPath, $message, $parameters, $value);
     $this->errors[] = array($message, $parameters, $value);
     return $this;
 }
示例#13
0
 public function checkStock($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if (null === $data["product_sale_elements_id"]) {
         $context->addViolationAt("quantity", Translator::getInstance()->trans("Invalid product_sale_elements"));
     } else {
         $productSaleElements = ProductSaleElementsQuery::create()->filterById($data["product_sale_elements_id"])->filterByProductId($data["product"])->findOne();
         $product = $productSaleElements->getProduct();
         if ($productSaleElements->getQuantity() < $value && $product->getVirtual() === 0 && ConfigQuery::checkAvailableStock()) {
             $context->addViolation(Translator::getInstance()->trans("quantity value is not valid"));
         }
     }
 }
示例#14
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;
 }
示例#15
0
 public function validateMethod(ExecutionContextInterface $context)
 {
     if ($this->fakerConfig && !in_array($this->getMethod(), array_keys($this->fakerConfig->getMethods()))) {
         $context->addViolationAt('method', 'This method \'{{ method }}\' is not available in Faker.', ['{{ method }}' => $this->getMethod()], null);
     }
 }
示例#16
0
 /**
  * @param ExecutionContextInterface $context
  */
 public function isStatusErroneous(ExecutionContextInterface $context)
 {
     if ($this->getBinaryContent() && $this->getProviderStatus() == self::STATUS_ERROR) {
         $context->addViolationAt('binaryContent', 'invalid', array(), null);
     }
 }
示例#17
0
 /**
  * undocumented function.
  *
  * @return void
  *
  * @author
  **/
 public function checkLink(ExecutionContextInterface $context)
 {
     $violation = false;
     // check if the name is actually a fake name
     switch ($this->getLinkType()) {
         case 'viewReference':
             $violation = $this->getPage() == null;
             break;
         case 'route':
             $violation = $this->getRoute() == null;
             break;
         case 'url':
             $violation = $this->getUrl() == null;
             break;
         case 'attachedWidget':
             $violation = $this->getAttachedWidget() == null;
             break;
         default:
             break;
     }
     if ($violation) {
         $context->addViolationAt('firstName', 'validator.link.error.message.' . $this->getLinkType() . 'Missing', [], null);
     }
 }
示例#18
0
 public static function checkEndTime($date_time, ExecutionContextInterface $context)
 {
     $date_time = trim($date_time);
     if (empty($date_time)) {
         return;
     }
     if (is_null(self::parseDateTime(trim($date_time)))) {
         $context->addViolationAt('ended_at', 'Can not parse end time');
     }
 }
示例#19
0
 public function isVendorWritable(ExecutionContextInterface $context)
 {
     try {
         $vendor = $this->getVendor();
         if ($vendor && $this->entityRepository->isVendorTaken($vendor, reset($this->maintainers))) {
             $context->addViolationAt('repository', 'The vendor is already taken by someone else. ' . 'You may ask them to add your package and give you maintainership access. ' . 'The packages already in that vendor namespace can be found at ' . '<a href="' . $this->router->generate('view_vendor', array('vendor' => $vendor)) . '">' . $vendor . '</a>', array(), null);
         }
     } catch (\Doctrine\ORM\NoResultException $e) {
     }
 }
示例#20
0
文件: Activite.php 项目: ARL64/moove
 /**
  * @Assert\Callback
  * Permet de vérifier dans un même formualaire que la date de fermeture de l'activité se trouve avant la date de rendez-vous
  * Permet de vérifier que le nombre de participants d'une activité est inférieur ou égal au nombre de places totales de l'activité
  */
 public function validate(ExecutionContextInterface $context)
 {
     if ($this->dateFermeture != '' && $this->dateHeureRDV < $this->dateFermeture) {
         $context->addViolationAt('dateFermeture', 'La date de fermeture n\'est pas valide. Elle doit être avant la date et heure de rendez-vous.', array(), null);
     }
     if ($this->nbPartipants > $this->nbPlaces) {
         $context->addViolationAt('nbParticipants', 'L\'activité est déjà pleine, vous ne pouvez pas la rejoindre.', [], null);
     }
 }
 public function checkPlainPassword(ExecutionContextInterface $context)
 {
     if (false !== stripos($this->password, $this->username)) {
         $context->addViolationAt('password', 'Password must not contain the username');
     }
 }
 /**
  * @param ExecutionContextInterface $context
  */
 public function ownCallback(ExecutionContextInterface $context)
 {
     $context->addViolationAt('email', 'own_callback_email_' . $this->getEmail());
 }
示例#23
0
 /**
  * @Assert\Callback(groups={"victoire"})
  */
 public function validate(ExecutionContextInterface $context)
 {
     $template = $this;
     $templateHasLayout = false;
     while ($template != null) {
         if ($template->getLayout() != null) {
             $templateHasLayout = true;
             return;
         }
         $template = $template->getTemplate();
     }
     if ($this->getLayout() == null) {
         $context->addViolationAt('layout', 'data.template.templateform.view.type.template.layout.validator_message', [], null);
     }
 }
示例#24
0
 /**
  * Se utiliza para verificar la cadena del DNI durante el registro o la actualización de perfil.
  * 
  * @param \Cupon\UsuarioBundle\Entity\ExecutionContextInterface $context
  */
 public function esDniValido(ExecutionContextInterface $context)
 {
     $dni = $this->getDni();
     // Comprobar que el formato sea correcto
     if (0 === preg_match("/\\d{1,8}[a-z]/i", $dni)) {
         $context->addViolationAt('dni', 'El DNI introducido no tiene el
         formato correcto (entre 1 y 8 números seguidos de una letra, sin guiones y sin
         dejar ningún espacio en blanco)', array(), null);
         return;
     }
     // Comprobar que la letra cumple con el algoritmo
     $numero = substr($dni, 0, -1);
     $letra = strtoupper(substr($dni, -1));
     if ($letra != substr("TRWAGMYFPDXBNJZSQVHLCKE", strtr($numero, "XYZ", "012") % 23, 1)) {
         $context->addViolationAt('dni', 'La letra no coincide con el número del DNI. Comprueba que has escrito bien tanto el número como la letra', array(), null);
     }
 }
示例#25
0
 public function isSubscriberBasicValid(\Symfony\Component\Validator\ExecutionContextInterface $context)
 {
     if ($this->getEnterpriseType() != Subscriber::ENTERPRISE_TYPE_PRIVATE) {
         if (is_null($this->getCompany())) {
             $context->addViolationAt('company', '会社名を入力する必要があります。', array(), null);
         }
         if (is_null($this->getCompanyKana())) {
             $context->addViolationAt('companyKana', '会社名のふりがなを入力する必要があります。', array(), null);
         }
     }
 }
示例#26
0
 public function isPackageUnique(ExecutionContextInterface $context)
 {
     try {
         if ($this->entityRepository->findOneByName($this->name)) {
             $context->addViolationAt('repository', 'A package with the name <a href="' . $this->router->generate('view_package', array('name' => $this->name)) . '">' . $this->name . '</a> already exists.', array(), null);
         }
     } catch (\Doctrine\ORM\NoResultException $e) {
     }
 }
 /**
  * @param BasicConstraintsEntity    $object
  * @param ExecutionContextInterface $context
  */
 public static function validateDirectStaticCallback($object, ExecutionContextInterface $context)
 {
     if (!$object->isValid) {
         $context->addViolationAt('email', 'direct_static_callback_email_' . $object->getEmail(), array(), null);
     }
 }
示例#28
0
 public function isPublicUrlValid(ExecutionContextInterface $context)
 {
     // Search for whitespaces
     if (preg_match("/\\s/", $this->getPublicUrl())) {
         $context->addViolationAt('publicUrl', 'public_profile_url_not_valid', array(), null);
     }
 }
示例#29
0
 public function isInquiryValid(ExecutionContextInterface $context)
 {
     if (null === $this->getSenderEmail() && null === $this->getSenderPhone()) {
         $context->addViolationAt('sender_email', 'Please provide an email address or a phone number', array(), null);
     }
 }
示例#30
0
 /**
  * @param ExecutionContextInterface $context
  *
  * @author Yohann Marillet
  */
 public function emptyDates(ExecutionContextInterface $context)
 {
     if (empty($this->dateStart)) {
         $context->addViolationAt($this->datesViolationsAt, 'La date de début ne peut être vide');
     }
     if (empty($this->dateEnd)) {
         $context->addViolationAt($this->datesViolationsAt, 'La date de fin ne peut être vide');
     }
 }