innmind/media-type

Model of media types

2.0.0 2022-01-15 17:07 UTC

This package is auto-updated.

Last update: 2022-07-23 11:37:44 UTC


README

Build Status codecov Type Coverage

Model to validate media types (follows RFC6838).

Installation

composer install innmind/media-type

Usage

use Innmind\MediaType\MediaType;

$type = MediaType::of('application/json+some-extension; charset=utf-8');
$type->topLevel(); // application
$type->subType(); // json
$type->suffix(); // some-extension
$type->parameters()->first()->name(); // charset
$type->parameters()->first()->value(); // utf-8
$type->toString(); // application/json+some-extension; charset=utf-8

If the values are incorrect it will throw an exception. Or you can use MediaType::maybe() that will return an instance of Innmind\Immutable\Maybe.