Set the value for a given attribute.

@param  string  $key
@param  mixed  $value
@return $this

@throws \InvalidArgumentException
430654
public function attribute($key, $value)
    {
        if (! in_array($key, $this->allowedAttributes)) {
            throw new InvalidArgumentException("Attribute [{$key}] does not exist.");
        }

        $this->attributes[Arr::get($this->aliases, $key, $key)] = $value;

        return $this;
    }
423761
protected function setValue($value)
    {
        if (is_string($value)) {
            $this->value = $value;
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($value). "' for argument 'value' given."
            );
        }

        return $this;
    }
944178
protected function setMappedAttribute($key, $value)
    {
        $segments = explode('.', $this->getMappingForAttribute($key));

        $attribute = array_pop($segments);

        if ($target = $this->getTarget($this, $segments)) {
            $this->addTargetToSave($target);

            $target->{$attribute} = $value;
        }
    }
689408
public function addData($key, $value = null)
    {
        if (is_array($key)) {
            foreach ($key as $k => $v) {
                $this->data[$k] = $v;
            }
        }
        else if (is_string($key)) {
            $this->data[$key] = $value;
        }
        else {
            throw new \InvalidArgumentException(
                "invalid value provided for 'key'; expecting a key as a ".
                "string or an associative array"
            );
        }
        return $this;
    }
320080
public function with($attribute, $value)
    {
        $attribute = $this->snake($attribute);

        if (!$this->validate($attribute, $value)) {
            throw new InvalidArgumentException("错误的属性值'{$attribute}'");
        }

        $this->attributes[$attribute] = $value;

        return $this;
    }
1162019
public function setValue($value) {
		if (!$this->isPrimitive($value)) {
			throw new \InvalidArgumentException('Use setValue() only for primitives and PhpConstant, anyway use setExpression() instead.');
		}
		$this->value = $value;
		$this->hasValue = true;

		return $this;
	}
929146
public function setAttribute($key, $value)
	{
		// Hash required fields when necessary
		if (in_array($key, $this->hashableAttributes) and ! empty($value))
		{
			$value = $this->hash($value);
		}

		return parent::setAttribute($key, $value);
	}
225478
public function setAttribute($attribute, $value)
    {
        if (is_string($attribute)) {
            if (false === strpos($attribute, '::')) {
                if (defined('\PDO::' . $attribute)) {
                    $attribute = '\PDO::' . $attribute;
                } else {
                    $attribute = __CLASS__ . '::' . $attribute;
                }
            }
            if (!defined($attribute)) {
                throw new InvalidArgumentException(sprintf(
                    'Invalid connection option/attribute name specified: "%s"',
                    $attribute
                ));
            }
            $attribute = constant($attribute);
        }
        switch ($attribute) {
            case self::PROPEL_ATTR_CACHE_PREPARES:
                $this->isCachePreparedStatements = $value;
                break;
            default:
                $this->connection->setAttribute($attribute, $value);
        }
    }
846700
protected function _set($key, $value)
    {
        if (!is_string($key)) {
            throw new Exception\InvalidArgumentException(
                "Key must be a string or a number: '$key' given"
            );
        }
        $this->_data[$key] = $value;
    }
1368217
public function setAttribute($key, $value = null)
    {
        if (is_array($key) && is_null($value)) {
            $this->attributes = $key;
        } else {
            array_set($this->attributes, $key, $value);
        }

        return $this;
    }
201804
public function setAttribute($key, $value)
    {
        // We will check for the presence of a mutator for the set operation
        // which simply lets the developers tweak the attribute as it is set on
        // the model, such as "json_encoding" an listing of data for storage.
        if ($this->hasSetMutator($key)) {
            $method = 'set'.studly_case($key).'Attribute';
            return $this->{$method}($value);
        }

        $this->attributes[$key] = $value;
    }
2780
public function setAttribute($key, $value)
    {
        if ($value !== null && $this->hasEnumCast($key)) {
            $enum = $this->enumCasts[$key];

            if ($value instanceOf $enum) {
                $this->attributes[$key] = $value->value;
            } else {
                $this->attributes[$key] = $enum::getInstance($value)->value;
            }

            return $this;
        }

        parent::setAttribute($key, $value);
    }
56703
public function setAttribute($key, $value)
	{
		if ($this->castOnSet() && $this->isCastableAttribute($key))
		{
			$value = $this->castAttribute($key, $value);
		}
		return parent::setAttribute($key, $value);
	}
825065
public function setAttribute($key, $value)
    {
        // First we will check for the presence of a mutator for the set operation
        // which simply lets the developers tweak the attribute as it is set on
        // the model, such as "json_encoding" an listing of data for storage.
        if ($this->hasSetMutator($key)) {
            $method = 'set' . Helper::studly($key) . 'Attribute';

            $this->{$method}($value);

            return;
        }
        if ($this->isJsonCastable($key)) {
            $value = json_encode($value);
        }
        $this->attributes[$key] = $value;
    }
550071
public function setParam($key, $value = null)
    {
        if (!$this->hasParam($key)) {
            throw new \InvalidArgumentException(sprintf('Cannot set %s as parameter cause this key does not exist.', $key));
        }

        if (is_object($value)) {
            throw new \InvalidArgumentException('Parameter\'s value cannot be type of object.');
        }

        $currentValue = $this->getParamValue($key);
        if (
            (null !== $value && null !== $currentValue)
            && (
                gettype($value) !== gettype($currentValue)
                && (
                    !(is_string($value) || is_integer($value))
                    || !(is_string($currentValue) || is_integer($currentValue))
                )
            )
        ) {
            throw new \InvalidArgumentException(sprintf(
                'Cannot replace %s\'s value, %s expected and %s given.',
                $key,
                gettype($currentValue),
                gettype($value)
            ));
        }

        if (null === $value) {
            unset($this->_parameters[$key]);
        } else {
            $this->_parameters[$key] = ['value' => $value];
        }

        return $this->getContentInstance();
    }
782376
public function set($key, $value)
    {
        if (!$value instanceof EmailBodyPart) {
            throw new InvalidArgumentException(
                sprintf(
                    '%s only accepts instances of %s. Tried to to set key %s.',
                    __FUNCTION__, EmailBodyPart::class, $key
                )
            );
        }

        parent::set($key, $value);
    }
1338788
public function setValue($value) {
		if(!in_array($value, self::VALID_VALUES)) {
			throw new InvalidArgumentException('Value is not valid.');
		}

		$this->value = $value;

		return $this;
	}