Ejemplo n.º 1
0
 /**
  * Metodo responsavel por criar o validator para min e max length
  *
  * @param integer $intMinLength
  * @param integer $intMaxLength
  * @return $this|bool
  */
 public function setMinAndMaxStringLengthValidator($intMinLength = 0, $intMaxLength = 0)
 {
     if (!$intMinLength && !$intMaxLength) {
         return false;
     }
     $objValidator = new StringLength(['min' => $intMinLength, 'max' => $intMaxLength]);
     $this->getValidatorChain()->attach($objValidator->setMessage($this->strMsgErrorNotEmpty));
     return $this;
 }
Ejemplo n.º 2
0
 public function getInputFilter()
 {
     if ($this->filter == null) {
         $this->filter = new InputFilter();
         $password = new Input('password');
         $password->setRequired(true);
         $password->setAllowEmpty(false);
         $length = new StringLength();
         $length->setMax(20);
         $length->setMin(5);
         $length->setMessage($this->translator->translate('newPassword.password.incorrectLength'), StringLength::TOO_LONG);
         $length->setMessage($this->translator->translate('newPassword.password.incorrectLength'), StringLength::TOO_SHORT);
         $password->getValidatorChain()->attach($length);
         $this->filter->add($password);
         $passowordRepeat = new Input('passwordRepeat');
         $passowordRepeat->setRequired(true);
         $passowordRepeat->setAllowEmpty(false);
         $passowordRepeat->getValidatorChain()->attach(new Identical('password'));
         $this->filter->add($passowordRepeat);
     }
     return $this->filter;
 }
Ejemplo n.º 3
0
 /**
  * Ensures that getMessageVariables() returns an array of
  * strings and that these strings that can be used as variables
  * in a message.
  */
 public function testGetMessageVariables()
 {
     $vars = $this->validator->getMessageVariables();
     $this->assertInternalType('array', $vars);
     $this->assertEquals(array('min', 'max'), $vars);
     $message = 'variables: %notvar% ';
     foreach ($vars as $var) {
         $message .= "%{$var}% ";
     }
     $this->validator->setMessage($message, StringLength::TOO_SHORT);
     $this->assertFalse($this->validator->isValid('abc'));
     $messages = $this->validator->getMessages();
     $this->assertEquals('variables: %notvar% 4 8 ', current($messages));
 }
Ejemplo n.º 4
0
 /**
  * @param number $min
  * @param number $max
  * @return StringLength
  */
 public static function lengthValidator($min = null, $max = null)
 {
     $validator = new StringLength(compact('min', 'max'));
     if (is_numeric($min) && is_numeric($max)) {
         $validator->setMessage(sprintf("Input tidak boleh kurang dari %s dan lebih dari %s.", $min, $max));
     } else {
         if (is_numeric($min)) {
             $validator->setMessage(sprintf("Input minimal %s karakter.", $min));
         } else {
             if (is_numeric($max)) {
                 $validator->setMessage(sprintf("Input maksimal %s karakter.", $max));
             } else {
                 $validator->setMessage("Input tidak valid.");
             }
         }
     }
     return $validator;
 }