_pattern, $value, $arr)) { $valid = true; } return $valid ? null : [$this->_message, []]; } public function validateAttribute($model, $attribute) { $valid = false; if (preg_match($this->_pattern, $model->$attribute, $arr)) { $valid = true; } $valid ?: $this->addError($model, $attribute, $this->_message); } }