/**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = $this->requiredValue === null ? Leaps::t('leaps', '{attribute} cannot be blank.') : Leaps::t('leaps', '{attribute} must be "{requiredValue}".');
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = Leaps::t('leaps', '{attribute} "{value}" has already been taken.');
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = Leaps::t('leaps', 'The verification code is incorrect.');
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (is_array($this->length)) {
         if (isset($this->length[0])) {
             $this->min = $this->length[0];
         }
         if (isset($this->length[1])) {
             $this->max = $this->length[1];
         }
         $this->length = null;
     }
     if ($this->encoding === null) {
         $this->encoding = Leaps::$app->charset;
     }
     if ($this->message === null) {
         $this->message = Leaps::t('leaps', '{attribute} must be a string.');
     }
     if ($this->min !== null && $this->tooShort === null) {
         $this->tooShort = Leaps::t('leaps', '{attribute} should contain at least {min, number} {min, plural, one{character} other{characters}}.');
     }
     if ($this->max !== null && $this->tooLong === null) {
         $this->tooLong = Leaps::t('leaps', '{attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}.');
     }
     if ($this->length !== null && $this->notEqual === null) {
         $this->notEqual = Leaps::t('leaps', '{attribute} should contain {length, number} {length, plural, one{character} other{characters}}.');
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->filter === null) {
         throw new InvalidConfigException('The "filter" property must be set.');
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = Leaps::t('leaps', '{attribute} must be either "{true}" or "{false}".');
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         switch ($this->operator) {
             case '==':
                 $this->message = Leaps::t('leaps', '{attribute} must be repeated exactly.');
                 break;
             case '===':
                 $this->message = Leaps::t('leaps', '{attribute} must be repeated exactly.');
                 break;
             case '!=':
                 $this->message = Leaps::t('leaps', '{attribute} must not be equal to "{compareValue}".');
                 break;
             case '!==':
                 $this->message = Leaps::t('leaps', '{attribute} must not be equal to "{compareValue}".');
                 break;
             case '>':
                 $this->message = Leaps::t('leaps', '{attribute} must be greater than "{compareValue}".');
                 break;
             case '>=':
                 $this->message = Leaps::t('leaps', '{attribute} must be greater than or equal to "{compareValue}".');
                 break;
             case '<':
                 $this->message = Leaps::t('leaps', '{attribute} must be less than "{compareValue}".');
                 break;
             case '<=':
                 $this->message = Leaps::t('leaps', '{attribute} must be less than or equal to "{compareValue}".');
                 break;
             default:
                 throw new InvalidConfigException("Unknown operator: {$this->operator}");
         }
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = Leaps::t('leaps', '{attribute} is invalid.');
     }
 }
Example #9
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->enableIDN && !function_exists('idn_to_ascii')) {
         throw new InvalidConfigException('In order to use IDN validation intl extension must be installed and enabled.');
     }
     if ($this->message === null) {
         $this->message = Leaps::t('leaps', '{attribute} is not a valid URL.');
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->pattern === null) {
         throw new InvalidConfigException('The "pattern" property must be set.');
     }
     if ($this->message === null) {
         $this->message = Leaps::t('leaps', '{attribute} is invalid.');
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = $this->integerOnly ? Leaps::t('leaps', '{attribute} must be an integer.') : Leaps::t('leaps', '{attribute} must be a number.');
     }
     if ($this->min !== null && $this->tooSmall === null) {
         $this->tooSmall = Leaps::t('leaps', '{attribute} must be no less than {min}.');
     }
     if ($this->max !== null && $this->tooBig === null) {
         $this->tooBig = Leaps::t('leaps', '{attribute} must be no greater than {max}.');
     }
 }
Example #12
0
 /**
  * Creates validator objects based on the validation rules specified in [[rules()]].
  * Unlike [[getValidators()]], each time this method is called, a new list of validators will be returned.
  * @return ArrayObject validators
  * @throws InvalidConfigException if any validation rule configuration is invalid
  */
 public function createValidators()
 {
     $validators = new ArrayObject();
     foreach ($this->rules() as $rule) {
         if ($rule instanceof Validator) {
             $validators->append($rule);
         } elseif (is_array($rule) && isset($rule[0], $rule[1])) {
             // attributes, validator type
             $validator = Validator::createValidator($rule[1], $this, (array) $rule[0], array_slice($rule, 2));
             $validators->append($validator);
         } else {
             throw new InvalidConfigException('Invalid validation rule: a rule must specify both attribute names and validator type.');
         }
     }
     return $validators;
 }
Example #13
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = Leaps::t('leaps', 'The format of {attribute} is invalid.');
     }
     if ($this->format === null) {
         $this->format = Leaps::$app->formatter->dateFormat;
     }
     if ($this->locale === null) {
         $this->locale = Leaps::$app->language;
     }
     if ($this->timeZone === null) {
         $this->timeZone = Leaps::$app->timeZone;
     }
     if ($this->min !== null && $this->tooSmall === null) {
         $this->tooSmall = Leaps::t('leaps', '{attribute} must be no less than {min}.');
     }
     if ($this->max !== null && $this->tooBig === null) {
         $this->tooBig = Leaps::t('leaps', '{attribute} must be no greater than {max}.');
     }
     if ($this->maxString === null) {
         $this->maxString = (string) $this->max;
     }
     if ($this->minString === null) {
         $this->minString = (string) $this->min;
     }
     if ($this->max !== null && is_string($this->max)) {
         $timestamp = $this->parseDateValue($this->max);
         if ($timestamp === false) {
             throw new InvalidConfigException("Invalid max date value: {$this->max}");
         }
         $this->max = $timestamp;
     }
     if ($this->min !== null && is_string($this->min)) {
         $timestamp = $this->parseDateValue($this->min);
         if ($timestamp === false) {
             throw new InvalidConfigException("Invalid min date value: {$this->min}");
         }
         $this->min = $timestamp;
     }
 }
Example #14
0
 /**
  * Validates the given data with the specified validation rules.
  * This method will create a DynamicModel instance, populate it with the data to be validated,
  * create the specified validation rules, and then validate the data using these rules.
  * @param array $data the data (name-value pairs) to be validated
  * @param array $rules the validation rules. Please refer to [[Model::rules()]] on the format of this parameter.
  * @return static the model instance that contains the data being validated
  * @throws InvalidConfigException if a validation rule is not specified correctly.
  */
 public static function validateData(array $data, $rules = [])
 {
     /* @var $model DynamicModel */
     $model = new static($data);
     if (!empty($rules)) {
         $validators = $model->getValidators();
         foreach ($rules as $rule) {
             if ($rule instanceof Validator) {
                 $validators->append($rule);
             } elseif (is_array($rule) && isset($rule[0], $rule[1])) {
                 // attributes, validator type
                 $validator = Validator::createValidator($rule[1], $model, (array) $rule[0], array_slice($rule, 2));
                 $validators->append($validator);
             } else {
                 throw new InvalidConfigException('Invalid validation rule: a rule must specify both attribute names and validator type.');
             }
         }
     }
     $model->validate();
     return $model;
 }
Example #15
0
 /**
  * @inheritdoc
  */
 public function validateAttribute($model, $attribute)
 {
     $value = $model->{$attribute};
     $validator = $this->getValidator();
     if ($validator instanceof FilterValidator && is_array($value)) {
         $filteredValue = [];
         foreach ($value as $k => $v) {
             if (!$validator->skipOnArray || !is_array($v)) {
                 $filteredValue[$k] = call_user_func($validator->filter, $v);
             }
         }
         $model->{$attribute} = $filteredValue;
     } else {
         $this->getValidator($model);
         // ensure model context while validator creation
         parent::validateAttribute($model, $attribute);
     }
 }
Example #16
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = Leaps::t('leaps', 'File upload failed.');
     }
     if ($this->uploadRequired === null) {
         $this->uploadRequired = Leaps::t('leaps', 'Please upload a file.');
     }
     if ($this->tooMany === null) {
         $this->tooMany = Leaps::t('leaps', 'You can upload at most {limit, number} {limit, plural, one{file} other{files}}.');
     }
     if ($this->wrongExtension === null) {
         $this->wrongExtension = Leaps::t('leaps', 'Only files with these extensions are allowed: {extensions}.');
     }
     if ($this->tooBig === null) {
         $this->tooBig = Leaps::t('leaps', 'The file "{file}" is too big. Its size cannot exceed {limit, number} {limit, plural, one{byte} other{bytes}}.');
     }
     if ($this->tooSmall === null) {
         $this->tooSmall = Leaps::t('leaps', 'The file "{file}" is too small. Its size cannot be smaller than {limit, number} {limit, plural, one{byte} other{bytes}}.');
     }
     if (!is_array($this->extensions)) {
         $this->extensions = preg_split('/[\\s,]+/', strtolower($this->extensions), -1, PREG_SPLIT_NO_EMPTY);
     } else {
         $this->extensions = array_map('strtolower', $this->extensions);
     }
     if ($this->wrongMimeType === null) {
         $this->wrongMimeType = Leaps::t('leaps', 'Only files with these MIME types are allowed: {mimeTypes}.');
     }
     if (!is_array($this->mimeTypes)) {
         $this->mimeTypes = preg_split('/[\\s,]+/', strtolower($this->mimeTypes), -1, PREG_SPLIT_NO_EMPTY);
     } else {
         $this->mimeTypes = array_map('strtolower', $this->mimeTypes);
     }
 }