/** * Returns source attribute * * @param string $attribute * @throws InvalidValueException * @return mixed */ public function getAttribute($attribute) { if ($this->source->canGetProperty($attribute)) { return $this->source->{$attribute}; } throw new InvalidValueException('Unknown attribute: ' . $attribute); }
/** * @param \yii\base\Model $model * * @return string */ public function getModelDirectory(Model $model) { if (!$model->canGetProperty('idAttribute')) { throw new \LogicException("Model {$model->className()} has not 'idAttribute' property"); } $modelName = $this->getShortClass($model); /** @noinspection PhpUndefinedFieldInspection */ $modelId = $model->{$model->idAttribute}; return $this->_getSubDirectory($modelName, $modelId); }
/** * @inheritdoc */ public function canGetProperty($name, $checkVars = true, $checkBehaviors = true) { if (parent::canGetProperty($name, $checkVars, $checkBehaviors)) { return true; } try { return $this->hasAttribute($name); } catch (\Exception $e) { // `hasAttribute()` may fail on base/abstract classes in case automatic attribute list fetching used return false; } }