public function attribute($attribute, $default = null)
{
if ($this->getIsNewRecord()) {
return null;
}
$this->loadAttributes();
$attributeName = $attribute instanceof Attribute ? $attribute->name : $attribute;
if (!array_key_exists($attributeName, $this->_attributesValues)) {
return $default;
}
//если атрибут имеет множество значений - вернем их массив
if (is_array($this->_attributesValues[$attributeName])) {
$values = [];
foreach ($this->_attributesValues[$attributeName] as $attribute) {
$value = $attribute->value($default);
if (is_null($value)) {
continue;
}
$values[] = $value;
}
return $values;
}
return $this->_attributesValues[$attributeName]->value($default);
}