MediaTypes
abstract class MediaTypes (View source)
Utility class for converting Internet Media Types to file extensions and vice versa.
"Internet Media Types" are registered through the IANA and were formerly known as "MIME types". Although "MIME" still exists in the context of emails, the term is outdated when speaking about media types for the web.
The static properties containing the actual mappings is derived from a freely available list provided by the Apache HTTPD project. It is generated by a script which can be found in the Scripts folder of the Flow package.
Constants
PATTERN_SPLITMEDIARANGE |
|
PATTERN_SPLITMEDIATYPE |
|
Methods
Returns a Media Type based on the filename extension
Returns a Media Type based on the file content
Returns the primary filename extension based on the given Media Type.
Returns all possible filename extensions based on the given Media Type.
Parses a RFC 2616 Media Type and returns its parts in an associative array.
Checks if the given media range and the media type match.
Strips off any parameters from the given media type and returns just the type and subtype in the format "type/subtype".
Details
static string
getMediaTypeFromFilename(string $filename)
Returns a Media Type based on the filename extension
static string
getMediaTypeFromFileContent(string $fileContent)
Returns a Media Type based on the file content
static string
getFilenameExtensionFromMediaType(string $mediaType)
Returns the primary filename extension based on the given Media Type.
static array
getFilenameExtensionsFromMediaType(string $mediaType)
Returns all possible filename extensions based on the given Media Type.
static array
parseMediaType(string $rawMediaType)
Parses a RFC 2616 Media Type and returns its parts in an associative array.
media-type = type "/" subtype *( ";" parameter)
The media type "text/html; charset=UTF-8" would be parsed and returned with the following array keys and values:
"type" => the type as a string, "text" "subtype" => the subtype as a string, "html" "parameters" => an array of parameter names and values, array("charset" => "UTF-8")
static bool
mediaRangeMatches(string $mediaRange, string $mediaType)
Checks if the given media range and the media type match.
The pattern used by this function splits each into media type and subtype and ignores possible additional parameters or extensions. The prepared types and subtypes are then compared and wildcards are considered in this process.
Media ranges are explained in RFC 2616, section 14.1. "Accept".
static string
trimMediaType(string $rawMediaType)
Strips off any parameters from the given media type and returns just the type and subtype in the format "type/subtype".