Neos\Flow\Http\Request::getNegotiatedMediaType PHP 메소드

getNegotiatedMediaType() 공개 메소드

Returns the best fitting IANA media type after applying the content negotiation rules on a possible Accept header.
public getNegotiatedMediaType ( array $supportedMediaTypes, boolean $trim = true ) : string
$supportedMediaTypes array A list of media types which are supported by the application / controller
$trim boolean If TRUE, only the type/subtype of the media type is returned. If FALSE, the full original media type string is returned.
리턴 string The media type and sub type which matched, NULL if none matched
    public function getNegotiatedMediaType(array $supportedMediaTypes, $trim = true)
    {
        $negotiatedMediaType = null;
        $acceptedMediaTypes = $this->getAcceptedMediaTypes();
        foreach ($acceptedMediaTypes as $acceptedMediaType) {
            foreach ($supportedMediaTypes as $supportedMediaType) {
                if (MediaTypes::mediaRangeMatches($acceptedMediaType, $supportedMediaType)) {
                    $negotiatedMediaType = $supportedMediaType;
                    break 2;
                }
            }
        }
        return $trim ? MediaTypes::trimMediaType($negotiatedMediaType) : $negotiatedMediaType;
    }