Sets a flag into a value.

@param int       $value The value to set the flag on.
@param int|array $flag  The flag(s) to be set.

@return int Returns the value with the flag on.
@throws \InvalidArgumentException
437823
public static function setOn($value, $flag)
    {
        if (!Int::is($value)) {
            throw new \InvalidArgumentException("The \$value parameter must be of type int.");
        }

        if (is_array($flag)) {
            $ret = $value;
            foreach ($flag as $item) {
                $ret = static::setOn($ret, $item);
            }

            return $ret;
        } elseif (!static::is($flag)) {
            throw new \InvalidArgumentException("The \$flag parameter must be of type int and a power of 2.");
        }

        return ($value | $flag);
    }
54228
public function set($argument, $value = null)
    {
        if (!is_array($argument)) {
            $argument = array($argument => $value);
        }

        return $this->setArguments($argument);
    }
279244
protected function vaidateValue($value, $element)
    {
        $toTest = $this->getCompareValue();
        if ($this->getCompareAttribute()) {
            $testElement = $element->getParent()->getElement($this->getCompareAttribute());
            if (!$testElement) {
                throw new InvalidArgumentException('Wrong attribute');
            }
            $toTest = $testElement->getValue();
        }
        $return = false;
        switch ($this->getOperator()) {
            case '!=':
                $return = $value != $toTest;
            break;
            case '!==':
                $return = $value !== $toTest;
            break;
            case '>':
                $return = $value > $toTest;
            break;
            case '>=':
                $return = $value >= $toTest;
            break;
            case '<':
                $return = $value < $toTest;
            break;
            case '<=':
                $return = $value <= $toTest;
            break;
            case '===':
                $return = $value === $toTest;
            break;
            case '==':
            default:
                $return = $value == $toTest;
            break;
        }

        return $return;
    }
151873
public function set($key, $value)
	{
		if ( ! $value instanceof Checkbox)
		{
			throw new \InvalidArgumentException('Only Checkboxs can be added to a CheckboxGroup');
		}

		return parent::set($key, $value);
	}
439728
public function setFlag(int $flag): void
    {
        if ($flag < 0 || $flag > static::MAX_FLAG) {
            throw new \InvalidArgumentException('Flag must be an unsigned integer on the range [0-255]');
        }

        $this->flag = $flag;
    }
1258086
public function setAccountId($value)
    {
        if ($value === null || $value === '') {
            $this->_accountId = null;
        } elseif (TypeCast::canCastToString($value)) {
            $this->_accountId = (string)$value;
        } else {
            throw new \InvalidArgumentException('Invalid account_id value type "' . gettype($value) . '"');
        }
    }
1099112
public function setPadding($value)
    {
        if (!is_numeric($value) || $value < 0 || $value > 0.4) {
            throw new \InvalidArgumentException(
                "Padding '$value' out of range. ".
                "Values in the range [0.0, 0.4] are allowed.");
        }
        $this->padding = (float)$value;
        return $this;
    }
15467
protected function _checkFlags( $value )
	{
		$value = (int) $value;

		if( $value < MShop_Order_Item_Base_Product_Abstract::FLAG_NONE ||
			$value > MShop_Order_Item_Base_Product_Abstract::FLAG_IMMUTABLE ) {
				throw new MShop_Order_Exception( sprintf( 'Flags "%1$s" not within allowed range', $value ) );
		}
	}
963997
public function setFlags($flags)
    {
        if ($flags !== null) {
            if (! in_array($flags, [State::SAVED, State::DELETED, State::DELETED | State::SAVED], true)) {
                $message = 'Flags were %s, but need to be State::SAVED, State::DELETED or State::DELETED | State::SAVED';
                throw new InvalidArgumentException(sprintf($message, $flags));
            }

            $this->flags = $flags;
        }

        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;
    }
1280546
public function setFlags($flags)
    {
        if (!is_int($flags)) {
            throw new InvalidArgumentException('integer', 0);
        }

        if (($flags & FORCE_USE_PROC_OPEN) && ($flags & FORCE_USE_EXEC)) {
            throw new DomainException("Invalid flags: FORCE_USE_PROC_OPEN and FORCE_USE_EXEC cannot be set at the same time");
        }

        $this->flags = $flags;

        return $this;
    }
1083359
public function set($value): bool {
        //TODO throw exception instead?
        if (\is_int($value)) {
            $info = $this->getIndexAndMask($value);
            $i = $info["i"];
            $k = $info["k"];

            $flag = 1;
            $flag = $flag << $k;

            if (isset($this->array[$i])) {
                $this->array[$i] |= $flag;
            } else {
                $this->array[$i] = $flag;
            }
            return true;
        }
        return false;
    }
75091
public function setByMinute($value)
    {
        if (!is_integer($value) || $value < 0 || $value > 59) {
            throw new \InvalidArgumentException('Invalid value for BYMINUTE');
        }

        $this->byMinute = $value;

        $this->canUseBySetPos = true;

        return $this;
    }
666843
protected function modifyFlagValue($value)
    {
        $this->setDefaultLastValue('groupType', $this->getDefaultEnumValue());
        $flags = $this->getFlagFromLastValue($this->getLastValue());

        if (!in_array($this->flagName, self::SCOPES)) {
            $this->modifyBitmaskValue(
                $flags,
                $this->options['invert'] ? !$value : $value,
                $this->flagName
            );
        } else {
            $this->modifyGroupScopeBit($flags, $value);
        }

        return $flags->getValue();
    }
180132
public function setValue($value) {
		if ($value instanceof \ArrayObject)
			$this->value = $value->getArrayCopy();
		elseif (is_object($value))
			$this->value = get_object_vars($value);
		elseif (is_array($value))
			$this->value = $value;
		else
			throw new \InvalidArgumentException("Method 'setValue' expected an object or array value");
		
		return $this;
	}
1039805
public function setValue($value)
    {
        // If we're getting the data from json, we'll be receiving an object
        if ($value instanceof \StdClass) {
            $value = (array) $value;
        }

        if (is_array($value)) {
            $newVal = [];
            foreach ($value as $k => $v) {
                if (is_string($v)) {
                    $v = strtoupper($v);

                    // The value had multiple sub-values
                    if (false !== strpos($v, ',')) {
                        $v = explode(',', $v);
                    }
                    if (0 === strcmp($k, 'until')) {
                        $v = strtr($v, [':' => '', '-' => '']);
                    }
                } elseif (is_array($v)) {
                    $v = array_map('strtoupper', $v);
                }

                $newVal[strtoupper($k)] = $v;
            }
            $this->value = $newVal;
        } elseif (is_string($value)) {
            $this->value = self::stringToArray($value);
        } else {
            throw new \InvalidArgumentException('You must either pass a string, or a key=>value array');
        }
    }
1332810
public function offsetSet($offset, $value)
	{
		if ( ! is_scalar($offset))
		{
			throw new \InvalidArgumentException('Wrong offset value.');
		}
		
		$this->options[$offset] = $value;
		
		return $this;
	}