Index Documentation

MediaType
in package
implements Stringable, IComparable, IEquatable

Implements a structure for representing and comparing media/mime types.

Table of Contents

Interfaces

Stringable
IComparable
Provides an interface for comparison between objects. Allows for order/sorting instances.
IEquatable
Provides an interface for determining the value-equality of two objects.

Methods

__construct()  : mixed
__toString()  : string
compare()  : int
Compares the current instance with another and returns an integer that indicates whether the current object comes before or after or the same position and the other object.
compareCategory()  : int
Compares the category string with another one. Can be used for sorting.
compareKind()  : int
Compares the kind string with another one. Can be used for sorting.
compareSuffix()  : int
Compares the suffix string with another one. Can be used for sorting.
equals()  : bool
Checks whether the current object is equal to another.
fromPath()  : MediaType
Reads the media type of a given file path.
getCategory()  : string
Returns the media type category.
getCharset()  : string
Retrieves the charset parameter from the media type parameters.
getKind()  : string
Returns the media type kind.
getParam()  : mixed
Retrieves a media type parameter, or null if it is not present.
getParams()  : array<string, mixed>
Returns all media type parameters.
getQuality()  : float
Retrieves the q parameter from the media type parameters.
getSuffix()  : string
Returns the media type suffix.
hasParam()  : bool
Checks if a media type parameter is present.
matchCategory()  : bool
Matches the category string with another one.
matchKind()  : bool
Matches the kind string with another one.
matchSuffix()  : bool
Matches the suffix string with another one.
parse()  : MediaType
Parses a media type string into a MediaType object.

Methods

__construct()

public __construct(string $category, string $kind, string $suffix, array<string, mixed> $params) : mixed
Parameters
$category : string

Media type category.

$kind : string

Media type kind.

$suffix : string

Media type suffix.

$params : array<string, mixed>

Media type parameters.

__toString()

public __toString() : string
Return values
string

compare()

Compares the current instance with another and returns an integer that indicates whether the current object comes before or after or the same position and the other object.

public compare(mixed $other) : int
Parameters
$other : mixed
Return values
int

A value that indicates the relative order of the objects being compared. Less than zero for before, zero for same position, greater than zero for after.

compareCategory()

Compares the category string with another one. Can be used for sorting.

public compareCategory(string $category) : int
Parameters
$category : string

Category string to compare with.

Return values
int

0 if they are a match, something else if not.

compareKind()

Compares the kind string with another one. Can be used for sorting.

public compareKind(string $kind) : int
Parameters
$kind : string

Kind string to compare with.

Return values
int

0 if they are a match, something else if not.

compareSuffix()

Compares the suffix string with another one. Can be used for sorting.

public compareSuffix(string $suffix) : int
Parameters
$suffix : string

Suffix string to compare with.

Return values
int

0 if they are a match, something else if not.

equals()

Checks whether the current object is equal to another.

public equals(mixed $other) : bool
Parameters
$other : mixed
Return values
bool

true if the objects are equals, false if not.

fromPath()

Reads the media type of a given file path.

public static fromPath(string $path) : MediaType

Uses mime_content_type().

Parameters
$path : string

File path.

Tags
throws
RuntimeException

If $path does not exist.

Return values
MediaType

Media type of file.

getCategory()

Returns the media type category.

public getCategory() : string

Expected return values for this are 'application', 'audio', 'image', 'message', 'multipart', 'text', 'video', 'font', 'example', 'model', 'haptics' or '*' for wildcard.

Return values
string

Media type category.

getCharset()

Retrieves the charset parameter from the media type parameters.

public getCharset() : string
Return values
string

Character specified in media type.

getKind()

Returns the media type kind.

public getKind() : string
Return values
string

Media type kind.

getParam()

Retrieves a media type parameter, or null if it is not present.

public getParam(string $name[, int $filter = FILTER_DEFAULT ][, array<string, mixed>|int $options = 0 ]) : mixed
Parameters
$name : string

Media type parameter name.

$filter : int = FILTER_DEFAULT

A PHP filter extension filter constant.

$options : array<string, mixed>|int = 0

Options for the PHP filter.

Return values
mixed

Value of the parameter, null if not present.

getParams()

Returns all media type parameters.

public getParams() : array<string, mixed>
Return values
array<string, mixed>

Media type parameters

getQuality()

Retrieves the q parameter from the media type parameters.

public getQuality() : float
Return values
float

Quality specified for the media type.

getSuffix()

Returns the media type suffix.

public getSuffix() : string
Return values
string

Media type suffix.

hasParam()

Checks if a media type parameter is present.

public hasParam(string $name) : bool
Parameters
$name : string

Media type parameter name.

Return values
bool

true if the parameter is present.

matchCategory()

Matches the category string with another one.

public matchCategory(string $category) : bool
Parameters
$category : string

Category string to match with.

Return values
bool

true if they are a match.

matchKind()

Matches the kind string with another one.

public matchKind(string $kind) : bool
Parameters
$kind : string

Kind string to match with.

Return values
bool

true if they are a match.

matchSuffix()

Matches the suffix string with another one.

public matchSuffix(string $suffix) : bool
Parameters
$suffix : string

Suffix string to match with.

Return values
bool

true if they are a match.

parse()

Parses a media type string into a MediaType object.

public static parse(string $string) : MediaType
Parameters
$string : string

Media type string.

Return values
MediaType

Object representing the given string.


        
On this page

Search results