Helper for with()

@param Params $ret
@param string $key
@param string $value
@param bool $multiple
@return Params
480226
private static function doWith(Params $ret, $key, $value, $multiple = true)
    {
        if (!$multiple) {
            if (!is_scalar($value)) {
                throw new \InvalidArgumentException(
                    'Invalid argument $value to with(), expected scalar, got ' . gettype($value)
                );
            }
            if ($ret->contains($key, $value)) {
                $ret->remove($key, $value);
            } else {
                $ret->replace($key, [$value]);
            }
        } else {
            if ($ret->contains($key, $value)) {
                $ret->remove($key, $value);
            } else {
                $ret->add($key, $value);
            }
        }

        return $ret;
    }
374040
public function with( $key, $value = null ) {
		if ( is_array( $key ) ) {
			$this->data = array_merge( $this->data, $key );
		} else if ( is_object( $key ) && method_exists( $key, 'to_array' ) ) {
			$this->data = array_merge( $this->data, $key->to_array() );
		} else {
			$this->data[$key] = $value;
		}

		return $this;
	}
1028419
public function add_param($param, $value = null)
	{
		if ( ! is_array($param))
		{
			$param = array($param => $value);
		}

		foreach ($param as $key => $val)
		{
			\Arr::set($this->params, $key, $val);
		}
		return $this;
	}
78031
public function orWhere($key, $operator, $value)
    {
        $this->where[] = 'OR '.$key.' '.$operator.' '.'?';
        $this->bindings[] = $value;

        return $this;
    }
318103
public function add($key, $value)
    {
        if (!$key) {
            return $this;
        }

        $this->param[$key] = $value;

        return $this;
    }
1242601
public function setParam($key, $value)
        {
            $key = (string) $key;

            if ((null === $value) && isset($this->_params[$key])) {
                unset($this->_params[$key]);
            } elseif (null !== $value) {
                $this->_params[$key] = $value;
            }

            return $this;
        }
254142
public static void setParamDefault(
            final Multimap<String, String> params, final String key, final String value) {
        if (!params.containsKey(key)) {
            params.put(key, value);
        }
    }
986864
private function bindWhereClause($where, $multiple, $ar)
    {
        /*
         | Check if array given as where parameter, then
         | we will bind parameters into whereIn conditions
         */
        if (is_array($where) && $multiple == false) {
            $whr = array_keys($where);
            $this->where($this->quoteIdentifier($whr[0]), '=', $where[$whr[0]]);
        } elseif (is_array($where) && $multiple == true) {
            $this->whereIn($this->quoteIdentifier($ar->getKeyName()), 'IN', implode(',', $where));
        }

        /*
         | Check if string | int given as where parameter
         */
        if (is_string($where) || is_int($where)) {
            $this->where($this->quoteIdentifier($ar->getKeyName()), '=', $where);
        }
    }
595672
public function setUrlParameter($key, $value = null)
    {
        Argument::i()
            //argument 1 must be a string or array
            ->test(1, 'array', 'string')
            //argument 2 must be scalar
            ->test(2, 'scalar');

        if (is_array($key)) {
            $this->param = $key;
            return $this;
        }

        $this->param[$key] = $value;
    }
975846
private function param($key, $string, $value) {

        $field_required = false;

        // If the field name ends with a '*', the parameter is considered as required
        if (preg_match('/^(.+)\*$/', $key, $bits)) {

            $key = $bits[1];
            $field_required = true;

        }

        // The $value query object contains all regex which will be used by the collector to parse the route fields
        $value->setQuery($key, $string, $field_required);

        /* Every parameter can include it's own logic into the regular expression,
         * it can use backreferences and it's expected to be used against a single parameter.
         * This means that it can't be used as is to build the route regular expression,
         * Backreferences are not useful at this point and can make the regular expression more time consuming
         * and resource hungry. This is why they are replaced with the grouping parenthesis.
         * Eg: (value) changes in (?:value)
         *
         * Delimiting characters like '^' and '$' are also meaningless in the complete regular expression and
         * need to be removed. Contrariwise, wildcards must be delimited in order to keep the whole regular
         * expression consistent, hence a '?' is added to all the '.*' or '.+' that don't already have one.
         */
        $string = preg_replace("/(?<!\\\\)\\((?!\\?)/", '(?:', $string);
        $string = preg_replace("/\\.([\\*\\+])(?!\\?)/", '.${1}?', $string);
        $string = preg_replace("/^[\\^]/", '', $string);
        $string = preg_replace("/[\\$]$/", '', $string);

        /* The produced regular expression is grouped and associated with its key (this means that the 'preg_match'
         * function will generate an associative array where the key/value association is preserved).
         * If the field is required, the regular expression is completed with a '{1}' (which make it compulsory),
         * otherwise a '?' is added.
         */
        return '(?P<'.$key.'>'.$string.')'.(($field_required) ? '{1}' : '?');

    }
1321986
public function parameter($key, $value = NULL)
	{
		if (func_num_args() === 1)
		{
			if ( ! array_key_exists($key, $this->_parameters))
			{
				throw new \InvalidArgumentException('Parameter not set: '.$key);
			}
			return $this->_parameters[$key];
		}
		$this->_parameters[$key] = $value;
		return $this;
	}
1298385
public function setParameter($key, $value)
    {
        $path = explode('.', $key);

        $this->validateParameter($key, $value);


        $root = array();
        $r = &$root;
        foreach($path as $subNode) {
            $r[$subNode] = array();
            $r = &$r[$subNode];
        }
        $r = $value;
        $r = &$root;

        if ($this->parameters) {
            $parameters = $this->parameters->extract();
        }
        else {
            $parameters = array();
        }

        $this->parameters = new ArrayResolver(Arrays::mergeRecursiveUnique($parameters, $r));
        return $this;
    }
954467
protected function recursiveProcess(Parameter $param, &$value)
    {
        $type = $param->getType();

        if (!is_array($value)) {
            if ($type == 'array') {
                // Cast to an array if the value was a string, but should be an array
                $this->recursiveProcess($param->getItems(), $value);
                $value = array($value);
            }
        } elseif ($type == 'object') {
            $this->processObject($param, $value);
        } elseif ($type == 'array') {
            $this->processArray($param, $value);
        } elseif ($type == 'string' && gettype($value) == 'array') {
            $value = '';
        }

        if ($value !== null) {
            $value = $param->filter($value);
        }
    }
131533
public function param($key, $value)
    {
        $this->params = array_merge($this->params ?? [], [$key => $value]);
        return $this;
    }
397635
public function set($key, $value, $expire = 0, $useMillis = false, $existOption = null) {
        $payload = ['set', $key, $value];

        if ($expire !== 0) {
            $payload[] = $useMillis ? 'PX' : 'EX';
            $payload[] = $expire;
        }

        if ($existOption !== null) {
            $payload[] = $existOption;
        }

        return $this->send($payload, function ($response) {
            return (bool) $response;
        });
    }
1106528
protected function resolveRecursively(array $value, Parameter $param)
    {
        foreach ($value as $name => &$v) {
            switch ($param->getType()) {
                case 'object':
                    if ($subParam = $param->getProperty($name)) {
                        $key = $subParam->getWireName();
                        $value[$key] = $this->prepareValue($v, $subParam);
                        if ($name != $key) {
                            unset($value[$name]);
                        }
                    } elseif ($param->getAdditionalProperties() instanceof Parameter) {
                        $v = $this->prepareValue($v, $param->getAdditionalProperties());
                    }
                    break;
                case 'array':
                    if ($items = $param->getItems()) {
                        $v = $this->prepareValue($v, $items);
                    }
                    break;
            }
        }

        return $param->filter($value);
    }
1273726
public AsyncRestBuilder withParam(String key, String value) {
        this.params.put(key, value);
        return this;
    }