uiharu/src/MediaTypeExts.php

29 lines
754 B
PHP

<?php
namespace Uiharu;
use Index\MediaType;
final class MediaTypeExts {
public static function toV1(MediaType $mediaType): array {
$parts = [
'string' => (string)$mediaType,
'type' => $mediaType->getCategory(),
'subtype' => $mediaType->getKind(),
];
if(!empty($suffix = $mediaType->getSuffix()))
$parts['suffix'] = $suffix;
if(!empty($params = $mediaType->getParams()))
$parts['params'] = $params;
return $parts;
}
public static function isMedia(MediaType $mediaType): bool {
return $mediaType->matchCategory('image')
|| $mediaType->matchCategory('audio')
|| $mediaType->matchCategory('video');
}
}