/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/validators/RequiredValidator.php
55 строк
1 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\validators; use yii\helpers\Inflector; use Yii; /** * Валидатор проверки - что одно из двух полей заполнено * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2019 */ class RequiredValidator extends \yii\validators\RequiredValidator { /** * Массив параметров для проверки на обязательнось заполнения * @var null */ public $targetAttribute = []; /** * @inheritdoc */ public function init() { parent::init(); $this->message = Yii::t('app', 'One of param «{attributes}» must be set'); } /** * @inheritdoc */ public function validateAttribute($model, $attribute) { $is_required = true; foreach ($this->targetAttribute as $the_attribute) { if (!$this->isEmpty($model->{$the_attribute})) { $is_required = false; } } if ($is_required) { $params = [ 'attributes' => Inflector::sentence($this->targetAttribute, ' or '), ]; foreach ($this->targetAttribute as $the_attribute) { $this->addError($model, $the_attribute, $this->message, $params); } } } }