public function getBestEncodingMatch(
        IMediaTypeFormatter $formatter,
        array $acceptCharsetHeaders,
        ?MediaTypeHeaderValue $mediaTypeHeader
    ): ?string {
        $rankedAcceptCharsetHeaders = $this->rankAcceptCharsetHeaders($acceptCharsetHeaders);

        foreach ($rankedAcceptCharsetHeaders as $acceptCharsetHeader) {
            foreach ($formatter->getSupportedEncodings() as $supportedEncoding) {
                $charset = $acceptCharsetHeader->getCharset();

                if ($charset === '*' || strcasecmp($charset, $supportedEncoding) === 0) {
                    return $supportedEncoding;
                }
            }
        }

        if ($mediaTypeHeader === null || $mediaTypeHeader->getCharset() === null) {
            return null;
        }

        // Fall back to the charset in the media type header
        foreach ($formatter->getSupportedEncodings() as $supportedEncoding) {
            $charset = $mediaTypeHeader->getCharset();

            if ($charset === '*' || strcasecmp($charset, $supportedEncoding) === 0) {
                return $supportedEncoding;
            }
        }

        return null;
    }
public function getBestEncodingMatch(
        IMediaTypeFormatter $formatter,
        array $acceptCharsetHeaders,
        ?MediaTypeHeaderValue $mediaTypeHeader
    ): ?string {
        $rankedAcceptCharsetHeaders = $this->rankAcceptCharsetHeaders($acceptCharsetHeaders);

        foreach ($rankedAcceptCharsetHeaders as $acceptCharsetHeader) {
            foreach ($formatter->getSupportedEncodings() as $supportedEncoding) {
                $charset = $acceptCharsetHeader->getCharset();

                if ($charset === '*' || strcasecmp($charset, $supportedEncoding) === 0) {
                    return $supportedEncoding;
                }
            }
        }

        if ($mediaTypeHeader === null || $mediaTypeHeader->getCharset() === null) {
            return null;
        }

        // Fall back to the charset in the media type header
        foreach ($formatter->getSupportedEncodings() as $supportedEncoding) {
            $charset = $mediaTypeHeader->getCharset();

            if ($charset === '*' || strcasecmp($charset, $supportedEncoding) === 0) {
                return $supportedEncoding;
            }
        }

        return null;
    }
public function getBestEncodingMatch ( IMediaTypeFormatter $ formatter , array $ acceptCharsetHeaders , ? MediaTypeHeaderValue $ mediaTypeHeader ) : ? string { $ rankedAcceptCharsetHeaders = $ this -> rankAcceptCharsetHeaders ( $ acceptCharsetHeaders ) ; foreach ( $ rankedAcceptCharsetHeaders as $ acceptCharsetHeader ) { foreach ( $ formatter -> getSupportedEncodings ( ) as $ supportedEncoding ) { $ charset = $ acceptCharsetHeader -> getCharset ( ) ; if ( $ charset === '*' || strcasecmp ( $ charset , $ supportedEncoding ) === 0 ) { return $ supportedEncoding ; } } } if ( $ mediaTypeHeader === null || $ mediaTypeHeader -> getCharset ( ) === null ) { return null ; } // Fall back to the charset in the media type header foreach ( $ formatter -> getSupportedEncodings ( ) as $ supportedEncoding ) { $ charset = $ mediaTypeHeader -> getCharset ( ) ; if ( $ charset === '*' || strcasecmp ( $ charset , $ supportedEncoding ) === 0 ) { return $ supportedEncoding ; } } return null ; }
Gets the best character encoding match for the input media type formatter

@param IMediaTypeFormatter $formatter The media type formatter to match against
@param AcceptCharsetHeaderValue[] $acceptCharsetHeaders The list of charset header values to match against
@param MediaTypeHeaderValue|null $mediaTypeHeader The matched media type header value if one was set, otherwise null
@return string|null The best charset if one was found, otherwise null
Gets the best character encoding match for the input media type formatter