作者:slava
项目:placemen
/**
* @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);
});
}
作者:Miroco
项目:yii2-flag-behavio
/**
* @inheritdoc
*/
public function attach($owner)
{
parent::attach($owner);
$validators = $owner->validators;
$validator = Validator::createValidator('safe', $owner, array_keys($this->attributes));
$validators->append($validator);
}
作者:Brother-Simo
项目:yii2-wecha
/**
* 各类型上传文件验证
* @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);
}
作者:cj
项目:QRCode-yii
/**
* @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);
}
}
}
作者:manyoubaby12
项目:imsho
/**
* @inheritdoc
*/
public function attach($owner)
{
parent::attach($owner);
$validators = $this->owner->getValidators();
$validator = Validator::createValidator('safe', $this->owner, 'template_id');
$validators->append($validator);
}
作者:nepster-we
项目:yii2-module-user
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->message === null) {
$this->message = Yii::t('users', 'SIMPLE_PASSWORD');
}
}
作者:webadmin8
项目:rzwebsys
public function init()
{
parent::init();
if ($this->message === null) {
$this->message = Yii::t('yii', '{attribute} "{value}" has already been taken.');
}
}
作者:phpson
项目:DeviceManagementSyste
/**
* @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}}.');
}
}
作者:phaniaps
项目:yiicom
/**
* @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}".');
}
}
作者:bupy
项目:yii2-snotif
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->message === null) {
$this->message = Module::t('ERROR_VALIDATE_ARRAY');
}
}
作者:ranmoo
项目:yii
/**
* @inheritdoc
*/
public function validateAttribute($model, $attribute)
{
if ($this->range instanceof \Closure) {
$this->range = call_user_func($this->range, $model, $attribute);
}
parent::validateAttribute($model, $attribute);
}
作者:jlorent
项目:yii2-validator
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (empty($this->className)) {
throw InvalidConfigException('Property "className" must be provided');
}
}
作者:extpoin
项目:yii2-cor
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->message === null) {
$this->message = \Yii::t('app', 'Неправильный формат телефона, ожидается формат +79001234567');
}
}
作者:dld
项目:yii2-component
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!$this->message) {
$this->message = \Yii::t('app', 'Given value has bad format');
}
}
作者:nirod
项目:yii2-phone-inpu
public function init()
{
if (!$this->message) {
$this->message = \Yii::t('yii', 'The format of {attribute} is invalid.');
}
parent::init();
}
作者:caron
项目:yii2-component
public function init()
{
parent::init();
if ($this->message === null) {
$this->message = \Yii::t('errors', 'Wrong phone format.');
}
}
作者:dstotij
项目:yii2-json-schema-validato
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->schemaEmpty === null) {
$this->schemaEmpty = 'The "schema" property must be set.';
}
if ($this->schemaNotString === null) {
$this->schemaNotString = 'The "schema" property must be a a string.';
}
if ($this->message === null) {
$this->message = Yii::t('app', '{property}: {message}.');
}
if ($this->notString === null) {
$this->notString = Yii::t('app', 'The value must be a string.');
}
if ($this->notJsonString === null) {
$this->notJsonString = Yii::t('app', 'The value must be a valid JSON string.');
}
if (empty($this->schema)) {
throw new InvalidConfigException($this->schemaEmpty);
}
if (!is_string($this->schema)) {
throw new InvalidConfigException($this->schemaNotString);
}
}
作者:lianghongl
项目:yii2-zh-c
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->message === null) {
switch ($this->operator) {
case '==':
$this->message = Yii::t('yii', '{attribute} must be repeated exactly.');
break;
case '===':
$this->message = Yii::t('yii', '{attribute} must be repeated exactly.');
break;
case '!=':
$this->message = Yii::t('yii', '{attribute} must not be equal to "{compareValue}".');
break;
case '!==':
$this->message = Yii::t('yii', '{attribute} must not be equal to "{compareValue}".');
break;
case '>':
$this->message = Yii::t('yii', '{attribute} must be greater than "{compareValue}".');
break;
case '>=':
$this->message = Yii::t('yii', '{attribute} must be greater than or equal to "{compareValue}".');
break;
case '<':
$this->message = Yii::t('yii', '{attribute} must be less than "{compareValue}".');
break;
case '<=':
$this->message = Yii::t('yii', '{attribute} must be less than or equal to "{compareValue}".');
break;
default:
throw new InvalidConfigException("Unknown operator: {$this->operator}");
}
}
}
作者:zhuravljo
项目:yii2-calc-validato
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->message === null) {
$this->message = 'Error in expression';
}
}
作者:tuyakho
项目:yii2-youtub
/**
* @inheritdoc
*/
public function validateAttribute($model, $attribute)
{
if ($this->urlFilter) {
$model->{$attribute} = $this->getCodeFromUrl($model->{$attribute});
}
parent::validateAttribute($model, $attribute);
}