InlineValidator.php 1.23 KB
Newer Older
w  
Qiang Xue committed
1 2
<?php
/**
w  
Qiang Xue committed
3
 * InlineValidator class file.
w  
Qiang Xue committed
4 5
 *
 * @link http://www.yiiframework.com/
w  
Qiang Xue committed
6
 * @copyright Copyright &copy; 2008-2012 Yii Software LLC
w  
Qiang Xue committed
7 8 9
 * @license http://www.yiiframework.com/license/
 */

w  
Qiang Xue committed
10 11
namespace yii\validators;

w  
Qiang Xue committed
12
/**
w  
Qiang Xue committed
13 14 15 16 17 18 19 20 21 22
 * InlineValidator represents a validator which is defined as a method in the object being validated.
 *
 * The validation method must have the following signature:
 *
 * ~~~
 * function foo($attribute, $params)
 * ~~~
 *
 * where `$attribute` refers to the name of the attribute being validated, while `$params`
 * is an array representing the additional parameters supplied in the validation rule.
w  
Qiang Xue committed
23 24
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
w  
Qiang Xue committed
25
 * @since 2.0
w  
Qiang Xue committed
26
 */
w  
Qiang Xue committed
27
class InlineValidator extends Validator
w  
Qiang Xue committed
28 29 30 31 32 33 34 35 36 37 38 39
{
	/**
	 * @var string the name of the validation method defined in the active record class
	 */
	public $method;
	/**
	 * @var array additional parameters that are passed to the validation method
	 */
	public $params;

	/**
	 * Validates the attribute of the object.
w  
Qiang Xue committed
40
	 * @param \yii\base\Model $object the object being validated
w  
Qiang Xue committed
41 42
	 * @param string $attribute the attribute being validated
	 */
w  
Qiang Xue committed
43
	public function validateAttribute($object, $attribute)
w  
Qiang Xue committed
44 45 46 47 48
	{
		$method = $this->method;
		$object->$method($attribute, $this->params);
	}
}