Parses a accpet header and returns the values in descending order of preference.

@param  string|null $headerValue Header value
@return array
324574
protected function parseAcceptHeader(?string $headerValue): array
	{
		$groupedAccepts = [];

		if(empty($headerValue))
		{
			return $groupedAccepts;
		}

		// Collect acceptable values

		foreach(explode(',', $headerValue) as $accept)
		{
			$quality = 1;

			if(strpos($accept, ';'))
			{
				// We have a quality so we need to split some more

				[$accept, $quality] = explode(';', $accept, 2);

				// Strip the "q=" part so that we're left with only the numeric value

				$quality = substr(trim($quality), 2);
			}

			$groupedAccepts[$quality][] = trim($accept);
		}

		// Sort in descending order of preference

		krsort($groupedAccepts);

		// Flatten array and return it

		return array_merge(...array_values($groupedAccepts));
	}
880935
public function getHeaderValue($name, $defaultValue = null)
    {
        $header = $this->getHeader($name);
        if ($header !== null) {
            return $header->getValue();
        }
        return $defaultValue;
    }
118498
public static function parseHeaders($headerstr=false) {
        if ( $headerstr === false ) $headerstr = self::getLastHeadersReceived();
        $lines = explode("\n",$headerstr);
        $headermap = array();

        foreach ($lines as $line) {
            $pos = strpos($line, ':');
            if ( $pos < 1 ) continue;
            $key = substr($line,0,$pos);
            $value = trim(substr($line, $pos+1));
            if ( strlen($key) < 1 || strlen($value) < 1 ) continue;
            $headermap[$key] = $value;
        }
        return $headermap;
    }
1123732
protected static function header($headerKey, $headerValue, ResponseContract $response = null)
    {
        if ($response) {
            $response->setHeader($headerKey, $headerValue);
        } else {
            ResponseKit::setHeader($headerKey, $headerValue);
        }
    }
374591
private static function parseAuthorizationHeader($header)
    {
        if (strpos($header, 'Basic') !== 0) {
            return false;
        }

        $header = explode(':', base64_decode(substr($header, 6)), 2);

        return [
            'username' => $header[0],
            'password' => isset($header[1]) ? $header[1] : null,
        ];
    }
45350
public function getCascadeOption($cascadeValue)
    {
        $defaultCascade = $this->getRegistry()->config->get(static::CFG_DEFAULT_CASCADE);
        if (empty($cascadeValue) && !empty($defaultCascade)) {
            return [$defaultCascade];
        }

        /** @var Validator $validator */
        $validator = $this->getRegistry()->validator->get(static::CFG_DEFAULT_CASCADE);

        $cascadeValue = array_map('strtolower', array_map('trim', explode(',', $cascadeValue)));
        $cascadeValue = array_intersect($cascadeValue, $validator->getChoices());
        $cascadeValue = array_filter($cascadeValue);
        if(empty($cascadeValue)) {
            return null;
        }

        return $cascadeValue;
    }
1352656
public static function parse_headers($headers)
    {
        $a_headers = array();
        $headers   = preg_replace('/\r?\n(\t| )+/', ' ', $headers);
        $lines     = explode("\n", $headers);
        $count     = count($lines);

        for ($i=0; $i<$count; $i++) {
            if ($p = strpos($lines[$i], ': ')) {
                $field = strtolower(substr($lines[$i], 0, $p));
                $value = trim(substr($lines[$i], $p+1));
                if (!empty($value)) {
                    $a_headers[$field] = $value;
                }
            }
        }

        return $a_headers;
    }
494305
private function aggregatedValues(string $header): array
    {
        $values = [];
        foreach (explode(',', $header) as $headerValue) {
            $headerValueParts = explode(';', $headerValue);
            $mediaType = trim(array_shift($headerValueParts));
            $attributes = [];
            foreach ($headerValueParts as $attribute) {
                list($attributeKey, $attributeValue) = explode('=', $attribute);
                $attributes[trim($attributeKey)] = trim($attributeValue);
            }

            if (!isset($attributes['q'])) {
                $attributes['q'] = '1.0';
            }

            $values[$mediaType] = $attributes;
        }

        uasort($values, function (array $a, array $b) {
            return $b['q'] <=> $a['q'];
        });

        return $values;
    }
744142
protected function _generateIdFromHeaderValue($headerValue) {		
		if (!is_callable($this->header_id_func)) {
			return "";
		}

		$idValue = call_user_func($this->header_id_func, $headerValue);
		if (!$idValue) {
			return "";
		}

		return ' id="' . $this->encodeAttribute($idValue) . '"';
	}
1371470
public function getSortOrder($newValue, $currentValue = null)
    {
        $sortOrder = $currentValue;

        if ($newValue !== null) {
            $sortOrder = $this->sortConverter->hash2SortOrder($newValue);
        }

        return $sortOrder;
    }
1181201
public function getNullableValue($defaultValue = self::NULLABLE_DEFAULT)
    {
        $isNullable = !$this->isNotNull();

        return $isNullable === $defaultValue ? ($this->isAlwaysNullable() ? $isNullable : null) : $isNullable;
    }
972859
private static function parseAcceptHeader($header): array
    {
        // empty array
        $accept = [];

        // check empty
        if (!$header || $header === '') {
            return $accept;
        }

        // make array from header
        $values = explode(',', $header);
        $values = array_map('trim', $values);

        foreach ($values as $a) {
            // the default quality is 1.
            $q = 1;
            // check if there is a different quality
            if (strpos($a, ';q=') || strpos($a, '; q=')) {
                // divide "mime/type;q=X" into two parts: "mime/type" i "X"
                [$a, $q] = preg_split('/;([ ]?)q=/', $a);
            }
            // remove other extension
            if (strpos($a, ';')) {
                $a = substr($a, 0, strpos($a, ';'));
            }

            // mime-type $a is accepted with the quality $q
            // WARNING: $q == 0 means, that isn’t supported!
            $accept[$a] = (float)$q;
        }
        arsort($accept);
        return $accept;
    }
419346
public function getOrderedElements($header)
    {
        if (!$header) {
            throw new InvalidArgument('The header string should not be empty.');
        }

        $elements = array();
        $orderKeys = array();
        foreach ($this->parseHeader($header) as $key => $h) {
            try {
                $element = $this->acceptFactory($h);
                $elements[] = $element;
                $orderKeys[] = [$element->getQuality(), $key, $element->getValue()];
            } catch (Exception\Exception $e) {
                // silently skip in case of invalid headers coming in from a client
            }
        }

        // sort based on quality and then original order. This is necessary as
        // to ensure that the first in the list for two items with the same
        // quality stays in that order in both PHP5 and PHP7.
        uasort($orderKeys, function ($a, $b) {
            $qA = $a[0];
            $qB = $b[0];

            if ($qA == $qB) {
                return $a[1] > $b[1];
            }

            return ($qA > $qB) ? -1 : 1;
        });

        $orderedElements = [];
        foreach ($orderKeys as $key) {
            $orderedElements[] = $elements[$key[1]];
        }

        return $orderedElements;
    }
45598
public function parseHeaders($src)
    {
        $headers = array();

        foreach ($src as $i) {
            $row = explode(':', $i, 2);

            // header with no key/value - HTTP response, get code and status
            if(!isset($row[1])){

                $matches = array();
                if(preg_match('#HTTP/[1-2]\.[0-1] ([0-9]{3})(.*)#si', $row[0], $matches)){
                    $headers['Code'] = $matches[1];
                    $headers['Status'] = trim($matches[2]);
                }

                continue;
            }

            $key = trim($row[0]);
            $val = trim($row[1]);
            $headers[$key] = $val;
        }
        return $headers;
    }
304099
public function header($header = null, $value = null) {
        if ($header === null) {
            $this->headers = [];
        } else if ($value === null) {
            unset($this->headers[ $header ]);
        } else {
            $this->headers[ $header ] = $header . ': ' . $value;
        }

        return $this;
    }
184572
private function parseHeaders($headerContent)
    {
        $headers = [];
        $headerParts = preg_split('/\\R/s', $headerContent, -1, PREG_SPLIT_NO_EMPTY);
        foreach ($headerParts as $headerPart) {
            if (strpos($headerPart, ':') === false) {
                continue;
            }

            [$headerName, $headerValue] = explode(':', $headerPart, 2);
            $headerName = strtolower(trim($headerName));
            $headerValue = trim($headerValue);

            if (strpos($headerValue, ';') === false) {
                $headers[$headerName] = $headerValue;
            } else {
                $headers[$headerName] = [];
                foreach (explode(';', $headerValue) as $part) {
                    $part = trim($part);
                    if (strpos($part, '=') === false) {
                        $headers[$headerName][] = $part;
                    } else {
                        [$name, $value] = explode('=', $part, 2);
                        $name = strtolower(trim($name));
                        $value = trim(trim($value), '"');
                        $headers[$headerName][$name] = $value;
                    }
                }
            }
        }

        return $headers;
    }
1104365
public function filter($value)
    {
        if (null === $value) {
            return null;
        }
        $this->checkValueIsArrayOrThrowException($value);

        $return = [];
        foreach ($value as $header => $condition) {
            $return[$header] = $this->conditionFilter->filter($condition);
        }

        return $return;
    }