src/POData/HttpProcessUtility.php
/**
     * Selects an acceptable MIME type that satisfies the Accepts header.
     * 
     * @param string $acceptTypesText Text for Accepts header.
     * @param string[] $availableTypes  Types that the server is willing to return, in descending order of preference.
     * 
     * @return string The best MIME type for the client.
     *
     * @throws HttpHeaderFailure
     */
Selects an acceptable MIME type that satisfies the Accepts header.

@param string $acceptTypesText Text for Accepts header.
@param string[] $availableTypes  Types that the server is willing to return, in descending order of preference.

@return string The best MIME type for the client.


Selects an acceptable MIME type that satisfies the Accepts header . @param string $acceptTypesText Text for Accepts header . @param string [] $availableTypes Types that the server is willing to return in descending order of preference . @return string The best MIME type for the client .
public static function selectMimeType($acceptTypesText, array $availableTypes)
    {
        $selectedContentType = null;
        $selectedMatchingParts = -1;
        $selectedQualityValue = 0;
        $selectedPreferenceIndex = PHP_INT_MAX;
        $acceptable = false;
        $acceptTypesEmpty = true;
        if (!is_null($acceptTypesText)) {
            $acceptTypes = self::mimeTypesFromAcceptHeaders($acceptTypesText);
            foreach ($acceptTypes as $acceptType) {
                $acceptTypesEmpty = false;
                for ($i = 0; $i < count($availableTypes); $i++) {
                    $availableType = $availableTypes[$i];
                    $matchRating = $acceptType->getMatchingRating($availableType);
                    if ($matchRating < 0) {
                        continue;
                    }
                    if ($matchRating > $selectedMatchingParts) {
                        $selectedContentType = $availableType;
                        $selectedMatchingParts = $matchRating;
                        $selectedQualityValue = $acceptType->getQualityValue();
                        $selectedPreferenceIndex = $i;
                        $acceptable = $selectedQualityValue != 0;
                    } else if ($matchRating == $selectedMatchingParts) {
                        $candidateQualityValue = $acceptType->getQualityValue();
                        if ($candidateQualityValue > $selectedQualityValue) {
                            $selectedContentType = $availableType;
                            $selectedQualityValue = $candidateQualityValue;
                            $selectedPreferenceIndex = $i;
                            $acceptable = $selectedQualityValue != 0;
                        } else if ($candidateQualityValue == $selectedQualityValue) {
                            if ($i < $selectedPreferenceIndex) {
                                $selectedContentType = $availableType;
                                $selectedPreferenceIndex = $i;
                            }
                        }
                    }
                }
            }
        }
        if ($acceptTypesEmpty) {
            $selectedContentType = $availableTypes[0];
        } else if (!$acceptable) {
            $selectedContentType = null;
        }
        return $selectedContentType;
    }
public static function selectMimeType ( $ acceptTypesText , array $ availableTypes ) { $ selectedContentType = null ; $ selectedMatchingParts = - 1 ; $ selectedQualityValue = 0 ; $ selectedPreferenceIndex = PHP_INT_MAX ; $ acceptable = false ; $ acceptTypesEmpty = true ; if ( ! is_null ( $ acceptTypesText ) ) { $ acceptTypes = self :: mimeTypesFromAcceptHeaders ( $ acceptTypesText ) ; foreach ( $ acceptTypes as $ acceptType ) { $ acceptTypesEmpty = false ; for ( $ i = 0 ; $ i < count ( $ availableTypes ) ; $ i ++ ) { $ availableType = $ availableTypes [ $ i ] ; $ matchRating = $ acceptType -> getMatchingRating ( $ availableType ) ; if ( $ matchRating < 0 ) { continue ; } if ( $ matchRating > $ selectedMatchingParts ) { $ selectedContentType = $ availableType ; $ selectedMatchingParts = $ matchRating ; $ selectedQualityValue = $ acceptType -> getQualityValue ( ) ; $ selectedPreferenceIndex = $ i ; $ acceptable = $ selectedQualityValue != 0 ; } else if ( $ matchRating == $ selectedMatchingParts ) { $ candidateQualityValue = $ acceptType -> getQualityValue ( ) ; if ( $ candidateQualityValue > $ selectedQualityValue ) { $ selectedContentType = $ availableType ; $ selectedQualityValue = $ candidateQualityValue ; $ selectedPreferenceIndex = $ i ; $ acceptable = $ selectedQualityValue != 0 ; } else if ( $ candidateQualityValue == $ selectedQualityValue ) { if ( $ i < $ selectedPreferenceIndex ) { $ selectedContentType = $ availableType ; $ selectedPreferenceIndex = $ i ; } } } } } } if ( $ acceptTypesEmpty ) { $ selectedContentType = $ availableTypes [ 0 ] ; } else if ( ! $ acceptable ) { $ selectedContentType = null ; } return $ selectedContentType ; }
Selects an acceptable MIME type that satisfies the Accepts header.
Selects an acceptable MIME type that satisfies the Accepts header .
// A more specific type wins. // A type with a higher q-value wins. // A type that is earlier in the availableTypes array wins.