public static function negotiateMediaType(array $acceptedMediaTypes, array $supportedMediaTypes, bool $trim = true):? string
    {
        $negotiatedMediaType = null;
        foreach ($acceptedMediaTypes as $acceptedMediaType) {
            foreach ($supportedMediaTypes as $supportedMediaType) {
                if (MediaTypes::mediaRangeMatches($acceptedMediaType, $supportedMediaType)) {
                    $negotiatedMediaType = $supportedMediaType;
                    break 2;
                }
            }
        }

        return ($trim && $negotiatedMediaType !== null ? MediaTypes::trimMediaType($negotiatedMediaType) : $negotiatedMediaType);
    }
public static function negotiateMediaType(array $acceptedMediaTypes, array $supportedMediaTypes, bool $trim = true):? string
    {
        $negotiatedMediaType = null;
        foreach ($acceptedMediaTypes as $acceptedMediaType) {
            foreach ($supportedMediaTypes as $supportedMediaType) {
                if (MediaTypes::mediaRangeMatches($acceptedMediaType, $supportedMediaType)) {
                    $negotiatedMediaType = $supportedMediaType;
                    break 2;
                }
            }
        }

        return ($trim && $negotiatedMediaType !== null ? MediaTypes::trimMediaType($negotiatedMediaType) : $negotiatedMediaType);
    }
public static function negotiateMediaType ( array $ acceptedMediaTypes , array $ supportedMediaTypes , bool $ trim = true ) : ? string { $ negotiatedMediaType = null ; foreach ( $ acceptedMediaTypes as $ acceptedMediaType ) { foreach ( $ supportedMediaTypes as $ supportedMediaType ) { if ( MediaTypes :: mediaRangeMatches ( $ acceptedMediaType , $ supportedMediaType ) ) { $ negotiatedMediaType = $ supportedMediaType ; break 2 ; } } } return ( $ trim && $ negotiatedMediaType !== null ? MediaTypes :: trimMediaType ( $ negotiatedMediaType ) : $ negotiatedMediaType ) ; }
Returns the best fitting IANA media type after applying the content negotiation
rules on the accepted media types.

@param array $acceptedMediaTypes A list of accepted media types according to a request.
@param array $supportedMediaTypes A list of media types which are supported by the application / controller
@param bool $trim If TRUE, only the type/subtype of the media type is returned. If FALSE, the full original media type string is returned.
@return string The media type and sub type which matched, NULL if none matched
Returns the best fitting IANA media type after applying the content negotiation rules on the accepted media types .