Set multiple headers from a key-value array

Existing values matching the specified field are replaced.
Header field names are NOT case-sensitive.

@param array
@throws \InvalidArgumentException
@return Response Returns the current object instance
195623
public function setAllHeaders(array $headerArray)
    {
        foreach ($headerArray as $field => $value) {
            $this->setHeader($field, $value);
        }

        return $this;
    }
1212972
public function setFieldsFromArray(Array $fields) {
    foreach ($fields as $field => $value) {
      $this->set($field, $value);
    }
    return $this;
  }
743538
public function copyToArray(array &$array)
    {
        $array['serviceName']                                 = $this->serviceName;
        $array['apiKey']                                      = $this->apiKey;
        $array['apiSecret']                                   = $this->apiSecret;
        $array['issuer']                                      = $this->issuer;
        $array['authorizationEndpoint']                       = $this->authorizationEndpoint;
        $array['tokenEndpoint']                               = $this->tokenEndpoint;
        $array['revocationEndpoint']                          = $this->revocationEndpoint;
        $array['supportedRevocationAuthMethods']              = LanguageUtility::convertArrayToStringArray($this->supportedRevocationAuthMethods);
        $array['userInfoEndpoint']                            = $this->userInfoEndpoint;
        $array['jwksUri']                                     = $this->jwksUri;
        $array['jwks']                                        = $this->jwks;
        $array['registrationEndpoint']                        = $this->registrationEndpoint;
        $array['supportedScopes']                             = LanguageUtility::convertArrayOfArrayCopyableToArray($this->supportedScopes);
        $array['supportedResponseTypes']                      = LanguageUtility::convertArrayToStringArray($this->supportedResponseTypes);
        $array['supportedGrantTypes']                         = LanguageUtility::convertArrayToStringArray($this->supportedGrantTypes);
        $array['supportedAcrs']                               = $this->supportedAcrs;
        $array['supportedTokenAuthMethods']                   = LanguageUtility::convertArrayToStringArray($this->supportedTokenAuthMethods);
        $array['supportedDisplays']                           = LanguageUtility::convertArrayToStringArray($this->supportedDisplays);
        $array['supportedClaimTypes']                         = LanguageUtility::convertArrayToStringArray($this->supportedClaimTypes);
        $array['supportedClaims']                             = $this->supportedClaims;
        $array['serviceDocumentation']                        = $this->serviceDocumentation;
        $array['supportedClaimLocales']                       = $this->supportedClaimLocales;
        $array['supportedUiLocales']                          = $this->supportedUiLocales;
        $array['policyUri']                                   = $this->policyUri;
        $array['tosUri']                                      = $this->tosUri;
        $array['description']                                 = $this->description;
        $array['accessTokenType']                             = $this->accessTokenType;
        $array['accessTokenDuration']                         = $this->accessTokenDuration;
        $array['refreshTokenDuration']                        = $this->refreshTokenDuration;
        $array['idTokenDuration']                             = $this->idTokenDuration;
        $array['authorizationResponseDuration']               = $this->authorizationResponseDuration;
        $array['authenticationCallbackEndpoint']              = $this->authenticationCallbackEndpoint;
        $array['authenticationCallbackApiKey']                = $this->authenticationCallbackApiKey;
        $array['authenticationCallbackApiSecret']             = $this->authenticationCallbackApiSecret;
        $array['supportedSnses']                              = LanguageUtility::convertArrayToStringArray($this->supportedSnses);
        $array['snsCredentials']                              = LanguageUtility::convertArrayOfArrayCopyableToArray($this->snsCredentials);
        $array['createdAt']                                   = LanguageUtility::orZero($this->createdAt);
        $array['modifiedAt']                                  = LanguageUtility::orZero($this->modifiedAt);
        $array['developerAuthenticationCallbackEndpoint']     = $this->developerAuthenticationCallbackEndpoint;
        $array['developerAuthenticationCallbackApiKey']       = $this->developerAuthenticationCallbackApiKey;
        $array['developerAuthenticationCallbackApiSecret']    = $this->developerAuthenticationCallbackApiSecret;
        $array['supportedDeveloperSnses']                     = LanguageUtility::convertArrayToStringArray($this->supportedDeveloperSnses);
        $array['developerSnsCredentials']                     = LanguageUtility::convertArrayOfArrayCopyableToArray($this->developerSnsCredentials);
        $array['clientsPerDeveloper']                         = $this->clientsPerDeveloper;
        $array['directAuthorizationEndpointEnabled']          = $this->directAuthorizationEndpointEnabled;
        $array['directTokenEndpointEnabled']                  = $this->directTokenEndpointEnabled;
        $array['directRevocationEndpointEnabled']             = $this->directRevocationEndpointEnabled;
        $array['directUserInfoEndpointEnabled']               = $this->directUserInfoEndpointEnabled;
        $array['directJwksEndpointEnabled']                   = $this->directJwksEndpointEnabled;
        $array['directIntrospectionEndpointEnabled']          = $this->directIntrospectionEndpointEnabled;
        $array['singleAccessTokenPerSubject']                 = $this->singleAccessTokenPerSubject;
        $array['pkceRequired']                                = $this->pkceRequired;
        $array['refreshTokenKept']                            = $this->refreshTokenKept;
        $array['errorDescriptionOmitted']                     = $this->errorDescriptionOmitted;
        $array['errorUriOmitted']                             = $this->errorUriOmitted;
        $array['clientIdAliasEnabled']                        = $this->clientIdAliasEnabled;
        $array['supportedServiceProfiles']                    = LanguageUtility::convertArrayToStringArray($this->supportedServiceProfiles);
        $array['tlsClientCertificateBoundAccessTokens']       = $this->tlsClientCertificateBoundAccessTokens;
        $array['mutualTlsValidatePkiCertChain']               = $this->mutualTlsValidatePkiCertChain;
        $array['introspectionEndpoint']                       = $this->introspectionEndpoint;
        $array['supportedIntrospectionAuthMethods']           = LanguageUtility::convertArrayToStringArray($this->supportedIntrospectionAuthMethods);
        $array['trustedRootCertificates']                     = $this->trustedRootCertificates;
        $array['authorizationSignatureKeyId']                 = $this->authorizationSignatureKeyId;
        $array['idTokenSignatureKeyId']                       = $this->idTokenSignatureKeyId;
        $array['userInfoSignatureKeyId']                      = $this->userInfoSignatureKeyId;
    }
616715
public function setRequestHeader($name, $value)
    {
        if (!is_string($name))
            throw new \InvalidArgumentException('Argument 1 expected to be string, '.gettype($name).' seen.');

        if (!is_string($value))
            throw new \InvalidArgumentException('Argument 2 expected to be string, '.gettype($value).' seen.');

        if (($name = trim($name)) === '')
            throw new \RuntimeException('Argument 1 cannot be empty string.');

        $this->requestHeaders[$name] = $value;

        return $this;
    }
1153356
public static function hashMap($array, $key, $value = null): array
    {
        if (! Assert::array($array)) {
            throw new InvalidArgumentException(
                '`Arr::hashMap` first parameter must be `array` or implements interface `ArrayAccess`'
            );
        }

        $hashMap = [];
        $key     = trim($key);
        $value   = trim($value);

        if (! empty($value)) {
            foreach ($array as $row) {
                $hashMap[$row[$key]] = $row[$value];
            }
        } else {
            foreach ($array as $row) {
                $hashMap[$row[$key]] = $row;
            }
        }

        return $hashMap;
    }
805486
protected function parseHeaders(array $headers)
	{
		$this->headers = array();

		// find and set the HTTP status code and reason
		$firstHeader = array_shift($headers);
		if (!preg_match('/^HTTP\/\d(\.\d)? [0-9]{3}/', $firstHeader)) {
			throw new \InvalidArgumentException('Invalid response header');
		}
		list(, $status) = explode(' ', $firstHeader, 2);
		$code = explode(' ', $status);
		$code = (int) $code[0];

		// special handling for HTTP 100 responses
		if ($code === 100) {
			// remove empty header lines between 100 and actual HTTP status
			foreach ($headers as $key => $header) {
				if ($header) {
					break;
				}
				unset($headers[$key]);
			}

			// start the process over with the 100 continue header stripped away
			return $this->parseHeaders($headers);
		}

		$this->statusText = $status;
		$this->statusCode = $code;

		foreach ($headers as $header) {
			// skip empty lines
			if (!$header) {
				continue;
			}

			$delimiter = strpos($header, ':');
			if (!$delimiter) {
				continue;
			}

			$key = trim(strtolower(substr($header, 0, $delimiter)));
			$val = ltrim(substr($header, $delimiter + 1));

			if (isset($this->headers[$key])) {
				if (is_array($this->headers[$key])) {
					$this->headers[$key][] = $val;
				} else {
					$this->headers[$key] = array($this->headers[$key], $val);
				}
			} else {
				$this->headers[$key] = $val;
			}
		}
	}
1272701
public static function set(&$array, $key, $value)
    {
        $key = static::normalizeKey($key);

        if ($key === null || $key === '')
        {
            return ($array = $value);
        }

        $keys = explode('.', $key);
        $last = array_pop($keys);
        $currentElement =& $array;

        foreach ($keys as $currentKey)
        {
            if (!array_key_exists($currentKey, $currentElement) || !is_array($currentElement[$currentKey]))
            {
                $currentElement[$currentKey] = [];
            }

            $currentElement =& $currentElement[$currentKey];
        }

        $currentElement[$last] = $value;

        return $array;
    }
490374
public static function fromPairs($array)
    {
        if (!is_array($array) && !($array instanceof \Traversable)) {
            throw new \InvalidArgumentException(sprintf(
                'Dictionary::fromPairs() argument must be array or Traversable, '
                . 'but is "%s".', gettype($array)
            ));
        }
        
        $result = new Dictionary();
        foreach ($array as $pair) {
            if (!is_array($pair) || !isset($pair[0]) || !isset($pair[1])) {
                throw new \InvalidArgumentException(
                    'Each element of array or Traversable passed to Dictionary::FromPairs()'
                    . ' must be two-elements array.'
                );
            }
            
            $result[$pair[0]] = $pair[1];
        }
        return $result;
    }
1317560
public static function fromResponseArray($responseArray)
    {
        if (!is_array($responseArray)) {
            throw new \InvalidArgumentException(
                'Argument is not array'
            );
        }
        if (!isset($responseArray['access_token'])) {
            throw new \InvalidArgumentException(
                'Access token is not available'
            );
        }
        if (!isset($responseArray['expires_in'])) {
            throw new \InvalidArgumentException(
                'Access token expiration date is not specified'
            );
        }
        return new static(
            $responseArray['access_token'],
            $responseArray['expires_in'] + time()
        );
    }
109178
public function setHeaders($key, $value = null)
    {
        if (is_array($key)) {
            foreach ($key as $a_key => $value) {
                $this->headers[strtolower($a_key)] = "$a_key: $value";
            }
        } elseif (empty($value)) {
            $this->headers[] = $key;
        } else {
            $this->headers[strtolower($key)] = "$key: $value";
        }

        return $this;
    }
270947
public function setResponse($response)
    {
        $allowedValues = $this->getResponseAllowableValues();
        if (!in_array($response, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'response', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['response'] = $response;

        return $this;
    }
376545
public function setHeaders(array $headers)
    {
        foreach ($headers as $key => $value) {
            $this->headers[$key] = $value;
        }

        return $this;
    }
1095919
public function select(array $fields)
    {
        if (empty($fields)) {
            throw new InvalidArgumentException('The field array must not be' .
                ' empty.');
        }

        foreach ($fields as $field) {
            $validationResult = QueryValidator::validateFieldName($field);
            if ($validationResult->isFailed()) {
                throw new InvalidArgumentException('The field array for' .
                    ' building the SELECT clause contains invalid field name.' .
                    ' Validation fail reason: ' .
                    $validationResult->getFailReason());
            }
        }

        // Flipping an array will create a new associative array. The keys of
        // the new associative array make a set of distinct fields.
        $distinctFields = array_flip($fields);
        $this->selectFields = array_keys($distinctFields);
    }
232835
public function setArray(array $array)
    {
        $this->array = array_values($array);
        $this->arraySize = count($this->array);
        $this->rewind();

        return $this;
    }
820300
public function setMultiple(array $headers): HeaderCollection
    {
        foreach ($headers as $key => $value) {
            $key = $this->getKey($key, true);
            $this->headers[$key] = $value;
        }
        return $this;
    }
514409
public function setQueryVariables($array)
    {
        if (! is_array($array)) {

            throw new InvalidArgumentException('Must pass an array to setQueryVariables()');
        }

        $parts = array();

        foreach ($array as $name => $value) {

            $name = urlencode($name);

            if (! is_null($value)) {

                $parts[] = $name . '=' . urlencode($value);

            } else {

                $parts[] = $name;
            }
        }

        $this->setQuery(implode('&', $parts));
    }
498401
public function withHeaders(array $headers)
    {
        $clone = clone $this;

        foreach ($headers as $name => $value) {
            $clone->headers->set($name, $value);
        }

        return $clone;
    }