Yii2 framework backup
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.
 
 
 
 
 

48 lines
1.3 KiB

<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yiiunit\data\validators;
use yii\validators\Validator;
class TestValidator extends Validator
{
private $_validatedAttributes = [];
private $_setErrorOnValidateAttribute = false;
public function validateAttribute($object, $attribute)
{
$this->markAttributeValidated($attribute);
if ($this->_setErrorOnValidateAttribute == true) {
$this->addError($object, $attribute, sprintf('%s##%s', $attribute, \get_class($object)));
}
}
protected function markAttributeValidated($attr, $increaseBy = 1)
{
if (!isset($this->_validatedAttributes[$attr])) {
$this->_validatedAttributes[$attr] = 1;
} else {
$this->_validatedAttributes[$attr] = $this->_validatedAttributes[$attr] + $increaseBy;
}
}
public function countAttributeValidations($attr)
{
return isset($this->_validatedAttributes[$attr]) ? $this->_validatedAttributes[$attr] : 0;
}
public function isAttributeValidated($attr)
{
return isset($this->_validatedAttributes[$attr]);
}
public function enableErrorOnValidateAttribute()
{
$this->_setErrorOnValidateAttribute = true;
}
}