Commit 5b0886f1 by Qiang Xue

Allow "on" and "attributes" to take either array or string for validators.

parent 447bad5a
......@@ -76,7 +76,8 @@ abstract class Validator extends Component
];
/**
* @var array list of attributes to be validated.
* @var array|string attributes to be validated by this validator. For multiple attributes,
* please specify them as an array; for single attribute, you may use either a string or an array.
*/
public $attributes = [];
/**
......@@ -88,7 +89,8 @@ abstract class Validator extends Component
*/
public $message;
/**
* @var array list of scenarios that the validator can be applied to.
* @var array|string scenarios that the validator can be applied to. For multiple scenarios,
* please specify them as an array; for single scenario, you may use either a string or an array.
*/
public $on = [];
/**
......@@ -131,7 +133,7 @@ abstract class Validator extends Component
* @param array $params initial values to be applied to the validator properties
* @return Validator the validator
*/
public static function createValidator($type, $object, array $attributes, $params = [])
public static function createValidator($type, $object, $attributes, $params = [])
{
$params['attributes'] = $attributes;
......@@ -156,6 +158,20 @@ abstract class Validator extends Component
}
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!is_array($this->attributes)) {
$this->attributes = (array)$this->attributes;
}
if (!is_array($this->on)) {
$this->on = (array)$this->on;
}
}
/**
* Validates the specified object.
* @param \yii\base\Model $object the data object being validated
* @param array|null $attributes the list of attributes to be validated.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment