示例#1
0
 /**
  * @inheritdoc
  */
 public function validate(ValidationItem $validationItem)
 {
     $elementInternalName = $this->validatedElement->getInternalName(true);
     $validationOutput = $validationItem->getChainedValidation()->getValidation($elementInternalName, true);
     $validationBridge = new ValidationItemBridge($validationItem, $validationOutput);
     $this->validator->validate($validationBridge);
 }
示例#2
0
文件: IsValid.php 项目: gsouf/uform
 public function validate(ValidationItem $validationItem)
 {
     if ($validationItem->getElement() instanceof Validatable) {
         $validationItem->getElement()->checkValidity($validationItem);
     } else {
         throw new Exception('Element is not validatable. It must be an instance of UForm\\Form\\Element\\Validatable');
     }
 }
示例#3
0
文件: Csrf.php 项目: gsouf/uform
 /**
  * @inheritdoc
  */
 public function validate(ValidationItem $validationItem)
 {
     if (!$this->csrfInterface->tokenIsValid($validationItem->getValue())) {
         $message = new Message('Csrf token is not valid', [], self::NOT_VALID);
         $validationItem->appendMessage($message);
         $validationItem->setInvalid();
     }
 }
示例#4
0
文件: File.php 项目: gsouf/uform
 public function checkValidity(ValidationItem $validationItem)
 {
     $value = $validationItem->getValue();
     if (!$value instanceof FileUpload && $value !== null) {
         $message = new Message('The data sent is not a valid file', [], self::NOT_VALID_NOT_A_FILE);
         $validationItem->appendMessage($message);
         $validationItem->setInvalid();
     }
 }
示例#5
0
 /**
  * Adds a validationItem to the internal validation list
  * @param ValidationItem $validation
  */
 public function addValidation(ValidationItem $validation)
 {
     $el = $validation->getElement();
     $name = $el->getName();
     $internalName = $el->getInternalName(true);
     if (null !== $name) {
         $this->validationsName[$el->getName(true, true)] = $internalName;
     }
     $this->validationsInternalName[$internalName] = $validation;
 }
示例#6
0
文件: AlphaNum.php 项目: gsouf/uform
 /**
  * @inheritdoc
  */
 public function validate(ValidationItem $validationItem)
 {
     $data = $validationItem->getValue();
     if ($this->allowSpaces) {
         $data = preg_replace('/\\s/', '', $data);
     }
     if (strlen($data) > 0 && !ctype_alnum($data)) {
         $message = new Validation\Message('The value must only contain numbers or letters', [], self::NOT_ALPHANUM);
         $validationItem->appendMessage($message);
         $validationItem->setInvalid();
     }
 }
示例#7
0
文件: Required.php 项目: gsouf/uform
 /**
  * @inheritdoc
  */
 public function validate(ValidationItem $validationItem)
 {
     $value = $validationItem->getLocalData()->getDataCopy();
     $element = $validationItem->getElement();
     if ($element instanceof Requirable) {
         $valid = $element->isDefined($validationItem);
     } else {
         $valid = is_array($value) && isset($value[$validationItem->getLocalName()]) && null !== $value[$validationItem->getLocalName()];
     }
     if (!$valid) {
         $message = new Validation\Message('Field is required', [], self::REQUIRED);
         $validationItem->appendMessage($message);
         $validationItem->setInvalid();
     }
     return true;
 }
示例#8
0
文件: SameAs.php 项目: gsouf/uform
 /**
  * @inheritdoc
  */
 public function validate(ValidationItem $validationItem)
 {
     $value1 = $validationItem->getValue();
     $value2 = $validationItem->findValue($this->sameElement);
     if ($value2 !== $value1) {
         $message = new Validation\Message('Fields %_tested-field_% and %_compare-field_% have different values', ['tested-field' => $validationItem->getElement()->getName(true, true), 'compare-field' => $this->sameElement], self::DIFFERENT);
         $validationItem->appendMessage($message);
         $validationItem->setInvalid();
     }
 }
示例#9
0
 /**
  * @inheritdoc
  */
 public function validate(ValidationItem $validationItem)
 {
     $value = $validationItem->getValue();
     $length = strlen($value);
     if ($this->minLength > 0 && $length < $this->minLength) {
         $message = new Validation\Message('String too short (less than %_min-length_% character)', ['min-length' => $this->minLength, 'string-length' => $length], self::TOO_SHORT);
         $validationItem->appendMessage($message);
         $validationItem->setInvalid();
     } elseif ($this->maxLength > 0 && $length > $this->maxLength) {
         $message = new Validation\Message('String too long (more than %_max-length_% character)', ['max-length' => $this->maxLength, 'string-length' => $length], self::TOO_LONG);
         $validationItem->appendMessage($message);
         $validationItem->setInvalid();
     }
 }
示例#10
0
文件: InRange.php 项目: gsouf/uform
 /**
  * @inheritdoc
  */
 public function validate(ValidationItem $validationItem)
 {
     $hasMatch = false;
     if (is_array($this->range)) {
         foreach ($this->range as $value) {
             if ($value == $validationItem->getValue()) {
                 $hasMatch = true;
                 break;
             }
         }
     } else {
         if ($this->range->valueIsInRange($validationItem->getLocalData()->getDataCopy())) {
             $hasMatch = true;
         }
     }
     if (!$hasMatch) {
         $validationItem->setInvalid();
         $value = $validationItem->getValue();
         $message = new Message('Value not valid', ['value' => $value], self::NOT_IN_RANGE);
         $validationItem->appendMessage($message);
     }
 }
示例#11
0
 /**
  * @inheritdoc
  */
 public function appendMessage($message, $elementName = null)
 {
     $this->bridgeOutput->appendMessage($message, $elementName);
 }
示例#12
0
文件: Element.php 项目: gsouf/uform
 /**
  * Internal use - prepare the validation object
  *
  * @param DataContext $localValues
  * @param FormContext $formContext
  * @throws \UForm\Exception
  */
 public function prepareValidation(DataContext $localValues, FormContext $formContext)
 {
     $validators = $this->getValidators();
     $v = new ValidationItem($localValues, $this, $formContext);
     $v->addValidators($validators);
     $formContext->getChainedValidation()->addValidation($v);
 }