Set primary

@param boolean $primary

@return Attribute

@throws \InvalidArgumentException
430656
public function setPrimary($primary)
    {
        if (!is_bool($primary)) {
            throw new \InvalidArgumentException('The attribute primary on the class Attribute has to be boolean (' . gettype($primary) . ('object' === gettype($primary) ? ' ' . get_class($primary) : '') . ' given).');
        }

        $this->primary = $primary;

        return $this;
    }
148930
public function removePrimaryAttribute(Attribute $primaryAttribute)
    {
        foreach ($this->primaryAttributes as $key => $primaryAttributeElement) {
            if ($primaryAttributeElement === $primaryAttribute) {
                unset($this->primaryAttributes[$key]);
                break;
            }
        }

        return $this;
    }
1307233
public function setAttribute($name, $value)
    {
        $primaryKeyNames = self::getPrimaryKeyName(true);

        $meta = self::getMeta();
        $name = $meta->getMappingName($name);

        if ($meta->hasField($name)) {
            $field = $meta->getField($name);
            $attributeName = $field->getAttributeName();

            if ($field->getSqlType()) {
                $platform = $this->getConnection()->getDatabasePlatform();
                $value = $field->convertToDatabaseValueSQL($value, $platform);

                if (in_array($attributeName, $primaryKeyNames)) {
                    // If new primary key is empty - mark model as new
                    if (empty($value)) {
                        $this->setIsNewRecord(true);
                    } elseif ($this->getAttribute($attributeName) != $value) {
                        // If current model isn't new and new primary key value != new value - mark model as new
                        $this->setIsNewRecord(true);
                    }
                }

                $this->attributes->setAttribute($attributeName, $value);
            } else {
                $this->related[$name] = $value;
            }
        } else {
            throw new Exception(get_class($this).' has no attribute named "'.$name.'".');
        }
    }
1139638
public function assign($user, bool $primary = false): bool
    {
        if ($this->limitExceeded()) {
            return false;
        }

        $this->users()->attach($user);

        // Set user's primary group
        if ($primary) {
            // Get user's model name
            $userModel = config('auth.providers.users.model');

            // In case $user is an integer, find the relevant model record
            if (is_int($user)) {
                $user = $userModel::find($user);
            }

            $user->primary_group_id = $this->id;
            $user->save();
        }

        return true;
    }
135759
public function setValue($value)
    {
        if ((\is_bool($value))) {
            $this->value = (bool) $value;
        } elseif (\is_object($value) && $value instanceof self) {
            $this->value = $value->getValue();
        } else {
            throw new \InvalidArgumentException('Expected boolean');
        }
    }
1152455
public static function load($primary, bool $applySetters = false)
    {
        $connection = self::getConnection();
        $primary = static::normalizePrimaryKeys($primary);
        $object = null;

        $query = $connection->createQuery();
        $result = $query->from(static::$table)
            ->where(function (WhereClause $whereClause) use ($primary) {
                foreach ($primary as $key => $value) {
                    $whereClause->and($key, '=', '?');
                }
            })->execute(array_values($primary));

        if ($result->count()) {
            $rowData = $result->fetch()->getData();

            foreach (self::getDateFields() as $dateField) {
                $rowData[$dateField] = date_create_from_format(
                    $connection->getDateFormat(),
                    $rowData[$dateField]
                );
            }

            $object = new static();
            $object->fill($rowData, $applySetters);
        }

        return $object;
    }
480904
public function setInstance($object, $abstract = null)
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException('$object must be an object');
        }
        if ($abstract === null) {
            //If $abstract is not specified, use $objects class
            $abstract = get_class($object);
        } elseif ($abstract[0] === '\\') {
            //Strip all leading backslashes
            $abstract = substr($abstract, 1);
        }
        $concrete = $this->findMostConcreteDefinition($abstract);
        if (isset($this->objects[$concrete])) {
            //If this class already has an instance, we'll return the old object
            $old = $this->objects[$concrete];
        } else {
            $old = false;
        }
        //Store the object
        $this->objects[$concrete] = $object;

        return $old;
    }
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();
    }
1064227
public function setAttribute($name)
    {
        if (!$this->isValidAttribute($name)) {
            throw new exception\InvalidArgumentException(sprintf(
                'Invalid attribute name "%s"', $name
            ));
        }

        $this->attribute = $name;
        return $this;
    }
765618
public function primary($primary = true)
    {
        $primary = (bool) $primary;

        $this->primary = $primary;

        if ($primary) {
            $this->signed = false;
            $this->allowNull = false;
            $this->autoIncrement = true;
            $this->default = false;
        }

        return $this;
    }
224083
public function setMinSize($minSize)
    {
        if (!is_int($minSize)) {
            throw new \InvalidArgumentException('The attribute minSize on the class Attribute has to be integer (' . gettype($minSize) . ('object' === gettype($minSize) ? ' ' . get_class($minSize) : '') . ' given).');
        }

        $this->minSize = $minSize;

        return $this;
    }
585140
public function setType($type)
    {
        if (! in_array($type, self::$types, true)) {
            throw new InvalidArgumentException(sprintf(
                '"%s" is not a valid type! Valid types: %s',
                $type,
                implode(', ', self::$types)
            ));
        }

        $this->type = $type;

        return $this;
    }
786418
public function setCustom($custom)
    {
        if (!is_callable($custom)) {
            throw new \InvalidArgumentException('"' . $custom . '" is not callable');
        }

        $this->custom = $custom;
        return $this;
    }
13170
public function setBody($body)
    {
        if (is_string($body)) {
            return $this->setStringBody($body);
        }

        if (!is_resource($body)) {
            throw new InvalidArgumentException('Body must be a stream !');
        }
        if (!stream_is_local($body)) {
            throw new InvalidArgumentException('Body must be a local stream !');
        }

        rewind($body);
        $this->body = $body;
    }
1174384
public function setData($data)
    {
        if (!$data instanceof \SimpleXMLElement) {
            throw new \InvalidArgumentException(__METHOD__ . ' argument should be instance of ' . \SimpleXMLElement::class);
        }

        $this->data = $data;

        return $this;
    }
523217
public function setGender($gender)
    {
        if (null !== $gender) {
            $gender = (string)$gender;

        }

        if (!in_array($gender, [
            null,
            (string)self::GENDER_MISS,
            (string)self::GENDER_MR,
            (string)self::GENDER_MRS,
        ], true)) {
            throw new InvalidArgumentException(sprintf("Invalid gender %s.", $gender));
        }

        $this->gender = $gender ? (int)$gender : null;

        return $this;
    }
336495
public function setName($name)
    {
        if ($this->isNameValid($name) !== true) {
            throw new InvalidArgumentException('The name is not valid.');
        }

        $this->name = $name;

        return $this;
    }