You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

13 years ago
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
13 years ago
* @license http://www.yiiframework.com/license/
*/
13 years ago
namespace yii\validators;
13 years ago
/**
13 years ago
* DefaultValueValidator sets the attribute to be the specified default value.
*
* DefaultValueValidator is not really a validator. It is provided mainly to allow
* specifying attribute default values when they are empty.
13 years ago
*
* @author Qiang Xue <qiang.xue@gmail.com>
13 years ago
* @since 2.0
13 years ago
*/
13 years ago
class DefaultValueValidator extends Validator
13 years ago
{
/**
* @var mixed the default value to be set to the specified attributes.
*/
public $value;
/**
* @var boolean this property is overwritten to be false so that this validator will
* be applied when the value being validated is empty.
13 years ago
*/
public $skipOnEmpty = false;
13 years ago
/**
* Validates the attribute of the object.
13 years ago
* @param \yii\base\Model $object the object being validated
13 years ago
* @param string $attribute the attribute being validated
*/
13 years ago
public function validateAttribute($object, $attribute)
13 years ago
{
if ($this->isEmpty($object->$attribute)) {
13 years ago
$object->$attribute = $this->value;
}
}
}