Exemplo n.º 1
0
 public function validateValue(\Ongoo\Component\Form\Field $field, $value)
 {
     try {
         return parent::validateValue($field, $value);
     } catch (\Ongoo\Component\Form\Exceptions\ErrorException $ex) {
         $message = $ex->getMessage();
         $context = $ex->getContext();
         $len = strlen($value);
         if ($this->maxLength === $this->minLength && $len != $this->minLength) {
             $message = 'length must be {0} characters';
             $context = array('{0}' => $this->minLength);
         } else {
             if ($this->minLength < $this->maxLength && ($this->minLength > $len || $len > $this->maxLength)) {
                 $message = 'length must be between {0} and {1} characters';
                 $context = array('{0}' => $this->minLength, '{1}' => $this->maxLength);
             } else {
                 if (is_null($this->maxLength) && $this->minLength > $len) {
                     $message = 'length must be greater than {0} characters';
                     $context = array('{0}' => $this->minLength);
                 } else {
                     if (!is_null($this->maxLength) && $len > $this->maxLength) {
                         $message = 'length must be lower than {0} characters';
                         $context = array('{0}' => $this->maxLength);
                     } else {
                         $message = 'you must set a valid value';
                     }
                 }
             }
         }
         throw new \Ongoo\Component\Form\Exceptions\ErrorException($field, $value, $value, $message, $context);
     }
 }
Exemplo n.º 2
0
 public function validateValue(\Ongoo\Component\Form\Field $field, $value)
 {
     try {
         return parent::validateValue($field, $value);
     } catch (\Ongoo\Component\Form\Exceptions\ErrorException $e) {
         throw new \Ongoo\Component\Form\Exceptions\ErrorException($e->getField(), $e->getInitialValue(), $e->getValue(), 'you must set a valid email');
     }
 }
Exemplo n.º 3
0
 public function validateValue(\Ongoo\Component\Form\Field $field, $value)
 {
     if (is_null($value)) {
         return $value;
     }
     try {
         parent::validateValue($field, "{$value}");
     } catch (\Ongoo\Component\Form\Exceptions\ErrorException $e) {
         throw new \Ongoo\Component\Form\Exceptions\ErrorException($e->getField(), $e->getInitialValue(), $e->getValue(), 'you must set a valid ' . $this->realType, $e->getContext());
     }
     settype($value, $this->type);
     if (!is_null($this->min) && $this->min > $value) {
         throw new \Ongoo\Component\Form\Exceptions\ErrorException($field, $value, $value, 'you must a number greater than {0}', array('{0}' => $this->min));
     }
     if (!is_null($this->max) && $this->max < $value) {
         throw new \Ongoo\Component\Form\Exceptions\ErrorException($field, $value, $value, 'you must a number lower than {0}', array('{0}' => $this->max));
     }
 }