src/POData/HttpProcessUtility.php
/**
     * Gets the appropriate MIME type for the request, throwing if there is none.
     * 
     * @param string        $acceptTypesText    Text as it appears in an HTTP
     *                                          Accepts header.
     * @param string[] $exactContentTypes  Preferred content type to match if an exact media type is given - this is in descending order of preference.
     *
     * @param string        $inexactContentType Preferred fallback content type for inexact matches.
     *
     * @return string One of exactContentType or inexactContentType.
     */
Gets the appropriate MIME type for the request, throwing if there is none.

@param string        $acceptTypesText    Text as it appears in an HTTP
Accepts header.
@param string[] $exactContentTypes  Preferred content type to match if an exact media type is given - this is in descending order of preference.

@param string        $inexactContentType Preferred fallback content type for inexact matches.

@return string One of exactContentType or inexactContentType.
Gets the appropriate MIME type for the request throwing if there is none . @param string $acceptTypesText Text as it appears in an HTTP Accepts header . @param string [] $exactContentTypes Preferred content type to match if an exact media type is given - this is in descending order of preference . @param string $inexactContentType Preferred fallback content type for inexact matches . @return string One of exactContentType or inexactContentType .
public static function selectRequiredMimeType($acceptTypesText,
        $exactContentTypes,
        $inexactContentType
    ) {
        $selectedContentType = null;
        $selectedMatchingParts = -1;
        $selectedQualityValue = 0;
        $acceptable = false;
        $acceptTypesEmpty = true;
        $foundExactMatch = false;
        if (!is_null($acceptTypesText)) {
            $acceptTypes = self::mimeTypesFromAcceptHeaders($acceptTypesText);
            foreach ($acceptTypes as $acceptType) {
                $acceptTypesEmpty = false;
                foreach ($exactContentTypes as $exactContentType) {
                    if (strcasecmp($acceptType->getMimeType(), $exactContentType) == 0) {
                        $selectedContentType = $exactContentType;
                        $selectedQualityValue = $acceptType->getQualityValue();
                        $acceptable = $selectedQualityValue != 0;
                        $foundExactMatch = true;
                        break;
                    }
                }
                if ($foundExactMatch) {
                    break;
                }
                $matchingParts 
                    = $acceptType->getMatchingRating($inexactContentType);
                if ($matchingParts < 0) {
                    continue;
                }
                if ($matchingParts > $selectedMatchingParts) {
                    $selectedContentType = $inexactContentType;
                    $selectedMatchingParts = $matchingParts;
                    $selectedQualityValue = $acceptType->getQualityValue();
                    $acceptable = $selectedQualityValue != 0;
                } else if ($matchingParts == $selectedMatchingParts) {
                    $candidateQualityValue = $acceptType->getQualityValue();
                    if ($candidateQualityValue > $selectedQualityValue) {
                        $selectedContentType = $inexactContentType;
                        $selectedQualityValue = $candidateQualityValue;
                        $acceptable = $selectedQualityValue != 0;
                    }
                }
            }
        }
        if (!$acceptable && !$acceptTypesEmpty) {
            throw new HttpHeaderFailure(
                Messages::unsupportedMediaType(),
                415
            );
        }
        if ($acceptTypesEmpty) {
            $selectedContentType = $inexactContentType;
        }
        return $selectedContentType;
    }
public static function selectRequiredMimeType ( $ acceptTypesText , $ exactContentTypes , $ inexactContentType ) { $ selectedContentType = null ; $ selectedMatchingParts = - 1 ; $ selectedQualityValue = 0 ; $ acceptable = false ; $ acceptTypesEmpty = true ; $ foundExactMatch = false ; if ( ! is_null ( $ acceptTypesText ) ) { $ acceptTypes = self :: mimeTypesFromAcceptHeaders ( $ acceptTypesText ) ; foreach ( $ acceptTypes as $ acceptType ) { $ acceptTypesEmpty = false ; foreach ( $ exactContentTypes as $ exactContentType ) { if ( strcasecmp ( $ acceptType -> getMimeType ( ) , $ exactContentType ) == 0 ) { $ selectedContentType = $ exactContentType ; $ selectedQualityValue = $ acceptType -> getQualityValue ( ) ; $ acceptable = $ selectedQualityValue != 0 ; $ foundExactMatch = true ; break ; } } if ( $ foundExactMatch ) { break ; } $ matchingParts = $ acceptType -> getMatchingRating ( $ inexactContentType ) ; if ( $ matchingParts < 0 ) { continue ; } if ( $ matchingParts > $ selectedMatchingParts ) { $ selectedContentType = $ inexactContentType ; $ selectedMatchingParts = $ matchingParts ; $ selectedQualityValue = $ acceptType -> getQualityValue ( ) ; $ acceptable = $ selectedQualityValue != 0 ; } else if ( $ matchingParts == $ selectedMatchingParts ) { $ candidateQualityValue = $ acceptType -> getQualityValue ( ) ; if ( $ candidateQualityValue > $ selectedQualityValue ) { $ selectedContentType = $ inexactContentType ; $ selectedQualityValue = $ candidateQualityValue ; $ acceptable = $ selectedQualityValue != 0 ; } } } } if ( ! $ acceptable && ! $ acceptTypesEmpty ) { throw new HttpHeaderFailure ( Messages :: unsupportedMediaType ( ) , 415 ) ; } if ( $ acceptTypesEmpty ) { $ selectedContentType = $ inexactContentType ; } return $ selectedContentType ; }
Gets the appropriate MIME type for the request, throwing if there is none.
Gets the appropriate MIME type for the request throwing if there is none .
// A more specific type wins. // A type with a higher q-value wins.