eZ\Publish\Core\REST\Common\Input\ParsingDispatcher::parseMediaTypeVersion PHP Method

parseMediaTypeVersion() protected method

Parses and returns the version from a MediaType.
protected parseMediaTypeVersion ( string $mediaType ) : string
$mediaType string Ex: text/html; version=1.1
return string An array with the mediatype string, stripped from the version, and the version (1.0 by default)
    protected function parseMediaTypeVersion($mediaType)
    {
        $version = '1.0';
        $contentType = explode('; ', $mediaType);
        if (count($contentType) > 1) {
            $mediaType = $contentType[0];
            foreach (array_slice($contentType, 1) as $parameterString) {
                if (($equalPos = strpos($contentType[1], '=')) === false) {
                    throw new Exceptions\Parser("Unknown parameter format: '{$parameterString}'");
                }
                list($parameterName, $parameterValue) = explode('=', $parameterString);
                if (trim($parameterName) === 'version') {
                    $version = trim($parameterValue);
                    break;
                }
            }
        }
        return [$mediaType, $version];
    }