Encode arrays for use in the expanded URI string

@param array $variable
@param array $value
@param string $operator
@param string $separator
@param $useQueryString
@return string
971377
protected static function encodeArrayVariable(array $variable, array $value, $operator, $separator, &$useQueryString)
    {
        $isAssociativeArray = self::isAssociative($variable);
        $keyValuePairs = [];

        foreach ($variable as $key => $var) {
            if ($isAssociativeArray) {
                $key = rawurlencode($key);
                $isNestedArray = is_array($var);
            } else {
                $isNestedArray = false;
            }

            if (!$isNestedArray) {
                $var = rawurlencode($var);
                if ($operator === '+' || $operator === '#') {
                    $var = self::decodeReservedDelimiters($var);
                }
            }

            if ($value['modifier'] === '*') {
                if ($isAssociativeArray) {
                    if ($isNestedArray) {
                        // allow for deeply nested structures
                        $var = strtr(http_build_query([$key => $var]), ['+' => '%20', '%7e' => '~']);
                    } else {
                        $var = $key . '=' . $var;
                    }
                } elseif ($key > 0 && $useQueryString) {
                    $var = $value['value'] . '=' . $var;
                }
            }

            $keyValuePairs[$key] = $var;
        }

        $expanded = '';
        if (empty($variable)) {
            $useQueryString = false;
        } elseif ($value['modifier'] === '*') {
            $expanded = implode($separator, $keyValuePairs);
            if ($isAssociativeArray) {
                // Don't prepend the value name when using the explode modifier with an associative array
                $useQueryString = false;
            }
        } else {
            if ($isAssociativeArray) {
                // The result must be a comma separated list of keys followed by their respective values
                // if the explode modifier is not set on an associative array
                foreach ($keyValuePairs as $k => &$v) {
                    $v = $k . ',' . $v;
                }
            }
            $expanded = implode(',', $keyValuePairs);
        }

        return $expanded;
    }
446071
protected function setValue(array &$row, string $value = null): ?string
    {
        switch (true) {
            case $this->extractor instanceof MultiStringExtractorInterface:
                return $this->extractor->set($this->trail, $row, $value);
            case $this->extractor instanceof StringExtractorInterface:
                return $this->extractor->set($row, $value);
            default:
                throw new \InvalidArgumentException('Unknown extractor type ' . \get_class($this->extractor));
        }
    }
1263192
private String urlEncode(Object value)
	{
		try {
			return URLEncoder.encode(value.toString(), UTF8.name());
		} catch (UnsupportedEncodingException e) { throw new RuntimeException(e); }
	}
693945
public function encode(Parser $parser, Node\Variable $var, $values)
    {
        $values    = (array)$values;
        $list      = isset($values[0]);
        $reserved  = $this->reserved;
        $maps      = static::$reserved_chars;
        $sep       = $this->sep;
        $assoc_sep = '=';

        // non-explode modifier always use ',' as a separator
        if ($var->options['modifier'] !== '*') {
            $assoc_sep = $sep = ',';
        }

        array_walk($values, function(&$v, $k) use ($assoc_sep, $reserved, $list, $maps) {

            $encoded = rawurlencode($v);

            // assoc? encode key too
            if (!$list) {
                $encoded = rawurlencode($k).$assoc_sep.$encoded;
            }

            // rawurlencode is compliant with 'unreserved' set
            if (!$reserved) {
                $v = $encoded;
            }

            // decode chars in reserved set
            else {

                $v = str_replace(
                    array_keys($maps),
                    $maps,
                    $encoded
                );
            }
        });

        return implode($sep, $values);
    }
898195
private function replaceVariablesString($value) {
    if (!is_string($value)) {
      return $value;
    }
    preg_match_all('/\{([^\{]+)\}/', $value, $variableMatches);
    $variables = $variableMatches[1];
    foreach($variables as $variable) {
      preg_match('/^([^:]+)[:]*(.*)$/', $variable, $matches);
      if (sizeof($matches > 0)) {
        $variableName = $matches[1];
        $parameters = $matches[2];
        $persistenceFacade = $this->getPersistenceFacade();

        // last_created_oid
        if ($variableName == 'last_created_oid') {
          $type = $parameters;
          if ($persistenceFacade->isKnownType($type)) {
            $oid = $persistenceFacade->getLastCreatedOID($type);
            $value = preg_replace("/{".$variable."}/", $oid, $value);
          }
        }

        // oid reference
        if ($persistenceFacade->isKnownType($variableName)) {
          $type = $variableName;
          $oid = $persistenceFacade->getLastCreatedOID($type);
          $value = $oid;
        }
      }
    }
    return $value;
  }
1060204
final public function queryOnString(string $query, string $default = '', string $separator = ', '): string
    {
        $array = $this->queryArrayOne($query);
        if (false === $array) {
            return $default;
        }
        return implode($separator, $array);
    }
1320058
protected function invalidOperatorAndValue($operator, $value)
    {
        $isOperator = in_array($operator, $this->operators);

        return is_null($value) && $isOperator && ! in_array($operator, ['=', '<>', '!=']);
    }
1286043
public static function part(string $string, string $separator, int $index, string $defaultValue = ''): string
    {
        if ($string !== '') {
            $string = explode($separator, $string);
            if (isset($string[$index])) {
                return $string[$index];
            }
        }
        return $defaultValue;
    }
1276551
private function prepareRowOperator(?string $operator, $value, int $key): string
    {
        if (!$operator) {
            $operator = is_array($value) ? 'IN' : '=';
        }

        if ($operator === 'IN' and !is_array($value)) {
            if ($key !== 0) {
                throw new SqlException('Row value should be an array in condition on key #' . $key . '.');
            }

            $operator = '=';
        }

        if ($operator !== 'IN' and is_array($value)) {
            throw new SqlException('Row value could not be an array in condition on key #' . $key . ' for operator `' . $operator . '`.');
        }

        return $operator;
    }
1205205
public function toQueryString($separator = '&', $encoding = PHP_QUERY_RFC3986)
    {
        return http_build_query($this->toArray(), null, $separator, $encoding);
    }
34246
protected static function dotNotationToArray($string, $value, array &$array)
    {
        $keys = explode('.', $string);
        foreach ($keys as $key) {
            $array = &$array[$key];
        }
        $array = ($value === 'true' || $value === 'false') ? $value === 'true' : $value;
    }
531631
protected function operatorForWhere($key, $operator = null, $value = null)
    {
        if (func_num_args() === 1) {
            $value = true;

            $operator = '=';
        }

        if (func_num_args() === 2) {
            $value = $operator;

            $operator = '=';
        }

        return function ($item) use ($key, $operator, $value) {
            $retrieved = data_get($item, $key);

            $strings = array_filter([$retrieved, $value], function ($value) {
                return is_string($value) || (is_object($value) && method_exists($value, '__toString'));
            });

            if (count($strings) < 2 && count(array_filter([$retrieved, $value], 'is_object')) == 1) {
                return in_array($operator, ['!=', '<>', '!==']);
            }

            switch ($operator) {
                default:
                case '=':
                case '==':  return $retrieved == $value;
                case '!=':
                case '<>':  return $retrieved != $value;
                case '<':   return $retrieved < $value;
                case '>':   return $retrieved > $value;
                case '<=':  return $retrieved <= $value;
                case '>=':  return $retrieved >= $value;
                case '===': return $retrieved === $value;
                case '!==': return $retrieved !== $value;
            }
        };
    }
201681
public function join(array $array, string $separator = ','): string
    {
        $result = '';

        foreach ($array as $item) {
            if (is_array($item)) {
                $result .= $this->join($item, $separator) . $separator;
            } else {
                $result .= $item . $separator;
            }
        }

        $result = substr($result, 0, 0 - strlen($separator));

        return $result;
    }
1360884
@SneakyThrows
    public static String urlEncode(final String value, final String encoding) {
        return URLEncoder.encode(value, encoding);
    }
593019
public static function toArray($stringOrArray, string $separator = '.'): array
    {
        if (is_string($stringOrArray)) {
            if (trim($stringOrArray) !== '') {
                $stringOrArray = explode($separator, $stringOrArray);
            }
        }
        if (!is_array($stringOrArray)) {
            return [];
        }
        return $stringOrArray;
    }
986718
public function format($operator, $value, &$states = [])
    {
        $defaults = [
            'schemas' => [],
            'aliases' => [],
            'schema' => null
        ];
        $states += $defaults;
        if (!isset($this->_formatters[$operator])) {
            throw new SqlException("Unexisting formatter `'{$operator}'`.");
        }
        $formatter = $this->_formatters[$operator];
        return $formatter($value, $states);
    }
171018
protected function setEnvironmentVariables(array $values, $prefix, $separator = '_')
    {
        foreach ($values as $variable => $value) {
            $name = $prefix . $separator . $variable;

            if (is_array($value)) {
                $this->setEnvironmentVariables($value, $name, $separator);
            } else {
                $this->setEnvironmentVariable($name, $value);
            }
        }
    }