MimeMap

EmptyMap extends AbstractMap
in package

Class for mapping file extensions to MIME types.

This class has no mapping defined. It can be used for feeding updates and for testing purposes.

Table of Contents

Properties

$backupMap  : array<string, array<int|string, array<string, array<int, string>>>>|null
A backup of the mapping between file extensions and MIME types.
$instance  : mixed
$map  : array<string, array<int|string, array<string, array<int, string>>>>
Mapping between file extensions and MIME types.

Methods

__construct()  : mixed
Constructor.
addTypeAlias()  : MimeMapInterface
Adds an alias of a MIME type.
addTypeDescription()  : MimeMapInterface
Adds a description of a MIME type.
addTypeExtensionMapping()  : MimeMapInterface
Adds a type-to-extension mapping.
backup()  : void
Backs up the map array.
getAliasTypes()  : array<int, string>
Gets the parent types of an alias.
getExtensionTypes()  : array<int, string>
Gets the content of an entry from the 'extensions' array.
getFileName()  : string
Returns the map's class fully qualified filename.
getInstance()  : MimeMapInterface
Returns the singleton.
getMapArray()  : array<string, array<int|string, array<string, array<int, string>>>>
Gets the map array.
getTypeAliases()  : array<int, string>
Gets the aliases of a MIME type.
getTypeDescriptions()  : array<int, string>
Gets the descriptions of a MIME type.
getTypeExtensions()  : array<int, string>
Gets the content of an entry from the 't' array.
hasAlias()  : bool
Determines if a MIME type alias exists.
hasExtension()  : bool
Determines if an entry exists from the 'extensions' array.
hasType()  : bool
Determines if a MIME type exists.
listAliases()  : array<int, string>
Lists all the MIME types aliases defined in the map.
listExtensions()  : array<int, string>
Lists all the extensions defined in the map.
listTypes()  : array<int, string>
Lists all the MIME types defined in the map.
removeType()  : bool
Removes the entire mapping of a type.
removeTypeAlias()  : bool
Removes a MIME type alias.
removeTypeExtensionMapping()  : bool
Removes a type-to-extension mapping.
reset()  : void
Resets the map array to the backup.
setExtensionDefaultType()  : MimeMapInterface
Changes the default MIME type for a file extension.
setTypeDefaultExtension()  : MimeMapInterface
Changes the default extension for a MIME type.
sort()  : MapInterface
Sorts the map.
addMapSubEntry()  : MapInterface
Adds an entry to the map.
getMapEntry()  : array<string, array<string|int, string>>
Gets the content of an entry of the map.
getMapSubEntry()  : array<int, string>
Gets the content of a subentry of the map.
listEntries()  : array<int, int|string>
Gets a list of entries of the map.
normalizeType()  : string
Normalizes a mime-type string to Media/Subtype.
removeAliasedTypesExtensionMapping()  : void
Removes aliased types extension mapping.
removeMapSubEntry()  : bool
Removes an entry from the map.
setValueAsDefault()  : MimeMapInterface
Sets a value as the default for an entry.

Properties

$backupMap

A backup of the mapping between file extensions and MIME types.

protected static array<string, array<int|string, array<string, array<int, string>>>>|null $backupMap

Used during the map update process.

$instance

protected static mixed $instance

$map

Mapping between file extensions and MIME types.

protected static array<string, array<int|string, array<string, array<int, string>>>> $map = []

Methods

__construct()

Constructor.

public __construct() : mixed

addTypeAlias()

Adds an alias of a MIME type.

public addTypeAlias(string $type, string $alias) : MimeMapInterface
Parameters
$type : string

A MIME type.

$alias : string

An alias of $type.

Return values
MimeMapInterface

addTypeDescription()

Adds a description of a MIME type.

public addTypeDescription(string $type, string $description) : MimeMapInterface
Parameters
$type : string

A MIME type.

$description : string

The description of the MIME type.

Return values
MimeMapInterface

addTypeExtensionMapping()

Adds a type-to-extension mapping.

public addTypeExtensionMapping(string $type, string $extension) : MimeMapInterface
Parameters
$type : string

A MIME type.

$extension : string

A file extension.

Return values
MimeMapInterface

backup()

Backs up the map array.

public backup() : void

getAliasTypes()

Gets the parent types of an alias.

public getAliasTypes(string $alias) : array<int, string>

There should not be multiple types for an alias.

Parameters
$alias : string

The alias to be found.

Return values
array<int, string>

getExtensionTypes()

Gets the content of an entry from the 'extensions' array.

public getExtensionTypes(string $extension) : array<int, string>
Parameters
$extension : string

The extension to be found.

Return values
array<int, string>

The mapped MIME types.

getFileName()

Returns the map's class fully qualified filename.

public getFileName() : string
Return values
string

getMapArray()

Gets the map array.

public getMapArray() : array<string, array<int|string, array<string, array<int, string>>>>
Return values
array<string, array<int|string, array<string, array<int, string>>>>

getTypeAliases()

Gets the aliases of a MIME type.

public getTypeAliases(string $type) : array<int, string>
Parameters
$type : string

The type to be found.

Return values
array<int, string>

The mapped aliases.

getTypeDescriptions()

Gets the descriptions of a MIME type.

public getTypeDescriptions(string $type) : array<int, string>
Parameters
$type : string

The type to be found.

Return values
array<int, string>

The mapped descriptions.

getTypeExtensions()

Gets the content of an entry from the 't' array.

public getTypeExtensions(string $type) : array<int, string>
Parameters
$type : string

The type to be found.

Return values
array<int, string>

The mapped file extensions.

hasAlias()

Determines if a MIME type alias exists.

public hasAlias(string $alias) : bool
Parameters
$alias : string

The alias to be found.

Return values
bool

hasExtension()

Determines if an entry exists from the 'extensions' array.

public hasExtension(string $extension) : bool
Parameters
$extension : string

The extension to be found.

Return values
bool

hasType()

Determines if a MIME type exists.

public hasType(string $type) : bool
Parameters
$type : string

The type to be found.

Return values
bool

listAliases()

Lists all the MIME types aliases defined in the map.

public listAliases([string|null $match = null ]) : array<int, string>
Parameters
$match : string|null = null

(Optional) a match wildcard to limit the list.

Return values
array<int, string>

listExtensions()

Lists all the extensions defined in the map.

public listExtensions([string|null $match = null ]) : array<int, string>
Parameters
$match : string|null = null

(Optional) a match wildcard to limit the list.

Return values
array<int, string>

listTypes()

Lists all the MIME types defined in the map.

public listTypes([string|null $match = null ]) : array<int, string>
Parameters
$match : string|null = null

(Optional) a match wildcard to limit the list.

Return values
array<int, string>

removeType()

Removes the entire mapping of a type.

public removeType(string $type) : bool
Parameters
$type : string

A MIME type.

Return values
bool

true if the mapping was removed, false if the type was not present.

removeTypeAlias()

Removes a MIME type alias.

public removeTypeAlias(string $type, string $alias) : bool
Parameters
$type : string

A MIME type.

$alias : string

The alias to be removed.

Return values
bool

true if the alias was removed, false if the alias was not present.

removeTypeExtensionMapping()

Removes a type-to-extension mapping.

public removeTypeExtensionMapping(string $type, string $extension) : bool
Parameters
$type : string

A MIME type.

$extension : string

The file extension to be removed.

Return values
bool

true if the mapping was removed, false if the mapping was not present.

reset()

Resets the map array to the backup.

public reset() : void

setExtensionDefaultType()

Changes the default MIME type for a file extension.

public setExtensionDefaultType(string $extension, string $type) : MimeMapInterface

Allows a MIME type alias to be set as default for the extension.

Parameters
$extension : string

A file extension.

$type : string

A MIME type.

Return values
MimeMapInterface

setTypeDefaultExtension()

Changes the default extension for a MIME type.

public setTypeDefaultExtension(string $type, string $extension) : MimeMapInterface
Parameters
$type : string

A MIME type.

$extension : string

A file extension.

Return values
MimeMapInterface

addMapSubEntry()

Adds an entry to the map.

protected addMapSubEntry(string $entry, string $entryKey, string $subEntry, string $value) : MapInterface

Checks that no duplicate entries are made.

Parameters
$entry : string

The main array entry.

$entryKey : string

The main entry value.

$subEntry : string

The sub entry.

$value : string

The value to add.

Return values
MapInterface

getMapEntry()

Gets the content of an entry of the map.

protected getMapEntry(string $entry, string $entryKey) : array<string, array<string|int, string>>
Parameters
$entry : string

The main array entry.

$entryKey : string

The main entry value.

Return values
array<string, array<string|int, string>>

The values of the entry, or empty array if missing.

getMapSubEntry()

Gets the content of a subentry of the map.

protected getMapSubEntry(string $entry, string $entryKey, string $subEntry) : array<int, string>
Parameters
$entry : string

The main array entry.

$entryKey : string

The main entry value.

$subEntry : string

The sub entry.

Return values
array<int, string>

The values of the subentry, or empty array if missing.

listEntries()

Gets a list of entries of the map.

protected listEntries(string $entry[, string|null $match = null ]) : array<int, int|string>
Parameters
$entry : string

The main array entry.

$match : string|null = null

(Optional) a match wildcard to limit the list.

Return values
array<int, int|string>

The list of the entries.

normalizeType()

Normalizes a mime-type string to Media/Subtype.

protected normalizeType(string $typeString) : string
Parameters
$typeString : string

MIME type string to parse.

Tags
throws
MalformedTypeException

when $typeString is malformed.

Return values
string

A MIME type string in the 'Media/Subtype' format.

removeAliasedTypesExtensionMapping()

Removes aliased types extension mapping.

protected removeAliasedTypesExtensionMapping(string $type, string $extension) : void
Parameters
$type : string

A MIME type.

$extension : string

The file extension to be removed.

removeMapSubEntry()

Removes an entry from the map.

protected removeMapSubEntry(string $entry, string $entryKey, string $subEntry, string $value) : bool
Parameters
$entry : string

The main array entry.

$entryKey : string

The main entry value.

$subEntry : string

The sub entry.

$value : string

The value to remove.

Return values
bool

true if the entry was removed, false if the entry was not present.

setValueAsDefault()

Sets a value as the default for an entry.

protected setValueAsDefault(string $entry, string $entryKey, string $subEntry, string $value) : MimeMapInterface
Parameters
$entry : string

The main array entry.

$entryKey : string

The main entry value.

$subEntry : string

The sub entry.

$value : string

The value to add.

Return values
MimeMapInterface

        
On this page

Search results