public function setAttribute($name, $value) { parent::setAttribute($name, $value); if (in_array($name, $this->attributeNames())) { $attributes = $this->getAttributeConfigs(); $config = $attributes[$name]; // Handle special case attribute types switch ($config['type']) { case AttributeType::Bool: if ($value) { $value = (bool) $value; } break; case AttributeType::Number: if ($value) { $value = floatval(number_format($value, $config['decimals'])); } break; } $this->{$name} = $value; return true; } else { return false; } }
/** * @inheritDoc BaseModel::setAttribute() * * @param string $name * @param mixed $value * * @return bool|null */ public function setAttribute($name, $value) { if ($name == 'plugins') { $value = PluginUpdateModel::populateModels($value); } parent::setAttribute($name, $value); }
/** * @inheritDoc BaseModel::setAttribute() * * @param string $name * @param mixed $value * * @return bool|null */ public function setAttribute($name, $value) { if ($name == 'releases') { $value = PluginNewReleaseModel::populateModels($value); } parent::setAttribute($name, $value); }
/** * Any permission attribute we set needs to be boolean. * Since Vanilla can add these columns at run time, we have to react at * run-time. */ public function setAttribute($key, $value) { if (str_contains($key, '.') && !array_key_exists($key, $this->rules)) { $this->getValidator()->addRule($key, 'boolean'); } return parent::setAttribute($key, $value); }
/** * Sets an attribute's value. * * @param string $name * @param mixed $value * @return bool */ public function setAttribute($name, $value) { // Set packages as an array if ($name == 'packages' && !is_array($value)) { if ($value) { $value = array_filter(ArrayHelper::stringToArray($value)); sort($value); } else { $value = array(); } } return parent::setAttribute($name, $value); }
public function setAttribute($name, $value) { if (in_array($name, $this->attributeNames()) && $this->getAttribute($name) === $value) { return true; } if (parent::setAttribute($name, $value)) { $this->_matchedParcels = null; $this->_matchedParcelsAtOffsets = null; $this->_cachedIds = null; $this->_cachedTotal = null; return true; } else { return false; } }
/** * Sets an attribute's value. * * In addition, clears the cached values when a new attribute is set. * * @param string $name * @param mixed $value * * @return bool */ public function setAttribute($name, $value) { // If this is an attribute, and the value is not actually changing, just return true so the matched elements // don't get cleared. if (in_array($name, $this->attributeNames()) && $this->getAttribute($name) === $value) { return true; } if (parent::setAttribute($name, $value)) { $this->_matchedElements = null; $this->_matchedElementsAtOffsets = null; $this->_cachedIds = null; $this->_cachedTotal = null; return true; } else { return false; } }
/** * @inheritDoc BaseModel::setAttribute() * * @param string $name * @param mixed $value * * @return bool */ public function setAttribute($name, $value) { if ($name == 'path' && !empty($value)) { $value = rtrim($value, '/') . '/'; } return parent::setAttribute($name, $value); }