当前位置: 首页>>代码示例>>PHP>>正文


PHP validators\Validator类代码示例

本文整理汇总了PHP中yii\validators\Validator的典型用法代码示例。如果您正苦于以下问题:PHP Validator类的具体用法?PHP Validator怎么用?PHP Validator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Validator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $validators = $owner->validators;
     foreach ($this->rules as $rule) {
         if ($rule instanceof Validator) {
             $validators->append($rule);
             $this->validators[] = $rule;
             // keep a reference in behavior
         } elseif (is_array($rule) && isset($rule[0], $rule[1])) {
             // attributes, validator type
             $validator = Validator::createValidator($rule[1], $owner, (array) $rule[0], array_slice($rule, 2));
             $validators->append($validator);
             $this->validators[] = $validator;
             // keep a reference in behavior
         } else {
             throw new InvalidConfigException('Invalid validation rule: a rule must specify both attribute names and validator type.');
         }
     }
     $owner->on(ActiveRecord::EVENT_BEFORE_INSERT, function () {
         $this->saveRelatedDir($this->txt, $this->id_field, $this->name_field, $this->classDir);
     });
     $owner->on(ActiveRecord::EVENT_BEFORE_UPDATE, function () {
         $this->saveRelatedDir($this->txt, $this->id_field, $this->name_field, $this->classDir);
     });
 }
开发者ID:slavam,项目名称:placement,代码行数:29,代码来源:BasicBehavior.php

示例2: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $validators = $owner->validators;
     $validator = Validator::createValidator('safe', $owner, array_keys($this->attributes));
     $validators->append($validator);
 }
开发者ID:Mirocow,项目名称:yii2-flag-behavior,代码行数:10,代码来源:FlagBehavior.php

示例3: checkFile

 /**
  * 各类型上传文件验证
  * @param $attribute
  * @param $params
  */
 public function checkFile($attribute, $params)
 {
     // 按照类型 验证上传
     switch ($this->type) {
         case Media::TYPE_IMAGE:
             $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'jpg', 'maxSize' => 1048576];
             // 1MB
             break;
         case Media::TYPE_THUMB:
             $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'jpg', 'maxSize' => 524288];
             // 64KB
             break;
         case Media::TYPE_VOICE:
             $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'amr, mp3', 'maxSize' => 2097152];
             // 2MB
             break;
         case Media::TYPE_VIDEO:
             $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'mp4', 'maxSize' => 10485760];
             // 10MB
             break;
         default:
             return;
     }
     $validator = Validator::createValidator($rule[1], $this, (array) $rule[0], array_slice($rule, 2));
     $validator->validateAttributes($this);
 }
开发者ID:Brother-Simon,项目名称:yii2-wechat,代码行数:31,代码来源:MediaForm.php

示例4: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     parent::attach($owner);
     if (!is_array($this->attributes) || empty($this->attributes)) {
         throw new InvalidParamException('Invalid or empty attributes array.');
     } else {
         foreach ($this->attributes as $attribute => $config) {
             if (!isset($config['path']) || empty($config['path'])) {
                 throw new InvalidParamException('Path must be set for all attributes.');
             }
             if (!isset($config['tempPath']) || empty($config['tempPath'])) {
                 throw new InvalidParamException('Temporary path must be set for all attributes.');
             }
             if (!isset($config['url']) || empty($config['url'])) {
                 $config['url'] = $this->publish($config['path']);
             }
             $this->attributes[$attribute]['path'] = FileHelper::normalizePath(Yii::getAlias($config['path'])) . DIRECTORY_SEPARATOR;
             $this->attributes[$attribute]['tempPath'] = FileHelper::normalizePath(Yii::getAlias($config['tempPath'])) . DIRECTORY_SEPARATOR;
             $this->attributes[$attribute]['url'] = rtrim($config['url'], '/') . '/';
             $validator = Validator::createValidator('string', $this->owner, $attribute);
             $this->owner->validators[] = $validator;
             unset($validator);
         }
     }
 }
开发者ID:cjq,项目名称:QRCode-yii2,代码行数:28,代码来源:UploadBehavior.php

示例5: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $validators = $this->owner->getValidators();
     $validator = Validator::createValidator('safe', $this->owner, 'template_id');
     $validators->append($validator);
 }
开发者ID:manyoubaby123,项目名称:imshop,代码行数:10,代码来源:TemplateBehavior.php

示例6: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = Yii::t('users', 'SIMPLE_PASSWORD');
     }
 }
开发者ID:nepster-web,项目名称:yii2-module-users,代码行数:10,代码来源:PasswordValidator.php

示例7: init

 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = Yii::t('yii', '{attribute} "{value}" has already been taken.');
     }
 }
开发者ID:webadmin87,项目名称:rzwebsys7,代码行数:7,代码来源:TreeUniqueValidator.php

示例8: init

 /**
  * @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 = Yii::$app->charset;
     }
     if ($this->message === null) {
         $this->message = Yii::t('yii', '{attribute} must be a string.');
     }
     if ($this->min !== null && $this->tooShort === null) {
         $this->tooShort = Yii::t('yii', '{attribute} should contain at least {min, number} {min, plural, one{character} other{characters}}.');
     }
     if ($this->max !== null && $this->tooLong === null) {
         $this->tooLong = Yii::t('yii', '{attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}.');
     }
     if ($this->length !== null && $this->notEqual === null) {
         $this->notEqual = Yii::t('yii', '{attribute} should contain {length, number} {length, plural, one{character} other{characters}}.');
     }
 }
开发者ID:phpsong,项目名称:DeviceManagementSystem,代码行数:31,代码来源:StringValidator.php

示例9: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = $this->requiredValue === null ? Yii::t('yii', '{attribute} cannot be blank.') : Yii::t('yii', '{attribute} must be "{requiredValue}".');
     }
 }
开发者ID:phaniapsr,项目名称:yiicomm,代码行数:10,代码来源:RequiredValidator.php

示例10: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = Module::t('ERROR_VALIDATE_ARRAY');
     }
 }
开发者ID:bupy7,项目名称:yii2-snotify,代码行数:10,代码来源:IsArray.php

示例11: validateAttribute

 /**
  * @inheritdoc
  */
 public function validateAttribute($model, $attribute)
 {
     if ($this->range instanceof \Closure) {
         $this->range = call_user_func($this->range, $model, $attribute);
     }
     parent::validateAttribute($model, $attribute);
 }
开发者ID:ranmoon,项目名称:yii2,代码行数:10,代码来源:RangeValidator.php

示例12: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->className)) {
         throw InvalidConfigException('Property "className" must be provided');
     }
 }
开发者ID:jlorente,项目名称:yii2-validators,代码行数:10,代码来源:IntegrityValidator.php

示例13: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->message === null) {
         $this->message = \Yii::t('app', 'Неправильный формат телефона, ожидается формат +79001234567');
     }
 }
开发者ID:extpoint,项目名称:yii2-core,代码行数:10,代码来源:PhoneValidator.php

示例14: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!$this->message) {
         $this->message = \Yii::t('app', 'Given value has bad format');
     }
 }
开发者ID:dlds,项目名称:yii2-components,代码行数:10,代码来源:ISOValidator.php

示例15: init

 public function init()
 {
     if (!$this->message) {
         $this->message = \Yii::t('yii', 'The format of {attribute} is invalid.');
     }
     parent::init();
 }
开发者ID:nirodg,项目名称:yii2-phone-input,代码行数:7,代码来源:PhoneInputValidator.php


注:本文中的yii\validators\Validator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。