Type
in package
implements
TypeInterface
Class for working with MIME types
Table of Contents
Interfaces
- TypeInterface
- Interface for Type objects.
Constants
- FULL_TEXT = 1
- Full format [e.g. image/jpeg; p="1"] for strings.
- FULL_TEXT_WITH_COMMENTS = 2
- Full format with comments [e.g. image/jpeg; p="1" (comment)] for strings.
- SHORT_TEXT = 0
- Short format [e.g. image/jpeg] for strings.
Properties
- $descriptions : array<int, string>
- MIME type descriptions.
- $map : MimeMapInterface
- The MIME types map.
- $media : string
- The MIME media type.
- $mediaComment : string|null
- The MIME media type comment.
- $parameters : array<string, TypeParameter>
- Optional MIME parameters.
- $subType : string
- The MIME media sub-type.
- $subTypeComment : string|null
- The MIME media sub-type comment.
Methods
- __construct() : mixed
- Constructor.
- addParameter() : void
- Add a parameter to this type
- buildTypesList() : array<int, int|string>
- Builds a list of MIME types existing in the map.
- getAliases() : array<int, string>
- Returns all the aliases related to the MIME type(s).
- getDefaultExtension() : string
- Returns the MIME type's preferred file extension.
- getDescription() : string
- Returns a description for the MIME type, if existing in the map.
- getExtensions() : array<int, string>
- Returns all the file extensions related to the MIME type(s).
- getMedia() : string
- Gets a MIME type's media.
- getMediaComment() : string
- Gets the MIME type's media comment.
- getParameter() : TypeParameter
- Get a MIME type's parameter.
- getParameters() : array<string|int, TypeParameter>
- Get the MIME type's parameters.
- getSubType() : string
- Gets a MIME type's subtype.
- getSubTypeComment() : string
- Gets the MIME type's subtype comment.
- hasDescription() : bool
- Checks if a description for the MIME type exists.
- hasMediaComment() : bool
- Checks if the MIME type has media comment.
- hasParameter() : bool
- Checks if the MIME type has a parameter.
- hasParameters() : bool
- Checks if the MIME type has any parameter.
- hasSubTypeComment() : bool
- Checks if the MIME type has subtype comment.
- isAlias() : bool
- Is this an alias?
- isExperimental() : bool
- Is this type experimental?
- isVendor() : bool
- Is this a vendor MIME type?
- isWildcard() : bool
- Is this a wildcard type?
- removeParameter() : void
- Remove a parameter from this type.
- setMedia() : TypeInterface
- Sets a MIME type's media.
- setMediaComment() : TypeInterface
- Sets the MIME type's media comment.
- setSubType() : TypeInterface
- Sets a MIME type's subtype.
- setSubTypeComment() : TypeInterface
- Sets the MIME type's subtype comment.
- toString() : string
- Create a textual MIME type from object values.
- wildcardMatch() : bool
- Perform a wildcard match on a MIME type
- getUnaliasedType() : TypeInterface
- Returns the unaliased MIME type.
Constants
FULL_TEXT
Full format [e.g. image/jpeg; p="1"] for strings.
public
mixed
FULL_TEXT
= 1
FULL_TEXT_WITH_COMMENTS
Full format with comments [e.g. image/jpeg; p="1" (comment)] for strings.
public
mixed
FULL_TEXT_WITH_COMMENTS
= 2
SHORT_TEXT
Short format [e.g. image/jpeg] for strings.
public
mixed
SHORT_TEXT
= 0
Properties
$descriptions
MIME type descriptions.
protected
array<int, string>
$descriptions
= []
$map read-only
The MIME types map.
protected
MimeMapInterface
$map
$media
The MIME media type.
protected
string
$media
$mediaComment
The MIME media type comment.
protected
string|null
$mediaComment
= null
$parameters
Optional MIME parameters.
protected
array<string, TypeParameter>
$parameters
= []
$subType
The MIME media sub-type.
protected
string
$subType
$subTypeComment
The MIME media sub-type comment.
protected
string|null
$subTypeComment
= null
Methods
__construct()
Constructor.
public
__construct(string $typeString[, string|null $mapClass = null ]) : mixed
The type string will be parsed and the appropriate class vars set.
Parameters
- $typeString : string
-
MIME type string to be parsed.
- $mapClass : string|null = null
-
(Optional) The FQCN of the map class to use.
addParameter()
Add a parameter to this type
public
addParameter(string $name, string $value[, string|null $comment = null ]) : void
Parameters
- $name : string
- $value : string
- $comment : string|null = null
buildTypesList()
Builds a list of MIME types existing in the map.
public
buildTypesList() : array<int, int|string>
If the current type is a wildcard, than all the types matching the wildcard will be returned.
Return values
array<int, int|string>getAliases()
Returns all the aliases related to the MIME type(s).
public
getAliases() : array<int, string>
If the current type is a wildcard, than all aliases of all the types matching the wildcard will be returned.
Return values
array<int, string>getDefaultExtension()
Returns the MIME type's preferred file extension.
public
getDefaultExtension() : string
Return values
stringgetDescription()
Returns a description for the MIME type, if existing in the map.
public
getDescription([bool $includeAcronym = false ]) : string
Parameters
- $includeAcronym : bool = false
-
(Optional) if true and an acronym description exists for the type, the returned description will contain the acronym and its description, appended with a comma. Defaults to false.
Return values
stringgetExtensions()
Returns all the file extensions related to the MIME type(s).
public
getExtensions() : array<int, string>
If the current type is a wildcard, than all extensions of all the types matching the wildcard will be returned.
Return values
array<int, string>getMedia()
Gets a MIME type's media.
public
getMedia() : string
Note: 'media' refers to the portion before the first slash.
Return values
stringgetMediaComment()
Gets the MIME type's media comment.
public
getMediaComment() : string
Return values
stringgetParameter()
Get a MIME type's parameter.
public
getParameter(string $name) : TypeParameter
Parameters
- $name : string
Return values
TypeParametergetParameters()
Get the MIME type's parameters.
public
getParameters() : array<string|int, TypeParameter>
Return values
array<string|int, TypeParameter>getSubType()
Gets a MIME type's subtype.
public
getSubType() : string
Return values
stringgetSubTypeComment()
Gets the MIME type's subtype comment.
public
getSubTypeComment() : string
Return values
stringhasDescription()
Checks if a description for the MIME type exists.
public
hasDescription() : bool
Return values
boolhasMediaComment()
Checks if the MIME type has media comment.
public
hasMediaComment() : bool
Return values
boolhasParameter()
Checks if the MIME type has a parameter.
public
hasParameter(string $name) : bool
Parameters
- $name : string
Return values
boolhasParameters()
Checks if the MIME type has any parameter.
public
hasParameters() : bool
Return values
boolhasSubTypeComment()
Checks if the MIME type has subtype comment.
public
hasSubTypeComment() : bool
Return values
boolisAlias()
Is this an alias?
public
isAlias() : bool
Return values
boolisExperimental()
Is this type experimental?
public
isExperimental() : bool
Note: Experimental types are denoted by a leading 'x-' in the media or subtype, e.g. text/x-vcard or x-world/x-vrml.
Return values
boolisVendor()
Is this a vendor MIME type?
public
isVendor() : bool
Note: Vendor types are denoted with a leading 'vnd. in the subtype.
Return values
boolisWildcard()
Is this a wildcard type?
public
isWildcard() : bool
Return values
boolremoveParameter()
Remove a parameter from this type.
public
removeParameter(string $name) : void
Parameters
- $name : string
setMedia()
Sets a MIME type's media.
public
setMedia(string $media) : TypeInterface
Parameters
- $media : string
Return values
TypeInterfacesetMediaComment()
Sets the MIME type's media comment.
public
setMediaComment([string|null $comment = null ]) : TypeInterface
Parameters
- $comment : string|null = null
-
(optional) a comment; when missing any existing comment is removed.
Return values
TypeInterfacesetSubType()
Sets a MIME type's subtype.
public
setSubType(string $subType) : TypeInterface
Parameters
- $subType : string
Return values
TypeInterfacesetSubTypeComment()
Sets the MIME type's subtype comment.
public
setSubTypeComment([string|null $comment = null ]) : TypeInterface
Parameters
- $comment : string|null = null
-
(optional) a comment; when missing any existing comment is removed.
Return values
TypeInterfacetoString()
Create a textual MIME type from object values.
public
toString([int $format = Type::FULL_TEXT ]) : string
This function performs the opposite function of parse().
Parameters
- $format : int = Type::FULL_TEXT
-
The format of the output string.
Return values
stringwildcardMatch()
Perform a wildcard match on a MIME type
public
wildcardMatch(string $wildcard) : bool
Example: $type = new Type('image/png'); $type->wildcardMatch('image/*');
Parameters
- $wildcard : string
-
Wildcard to check against.
Return values
bool —True if there was a match, false otherwise.
getUnaliasedType()
Returns the unaliased MIME type.
protected
getUnaliasedType() : TypeInterface
Return values
TypeInterface —$this if the current type is not an alias, the parent type if the current type is an alias.