innmind / media-type
媒体类型模型
2.2.0
2023-09-16 15:11 UTC
Requires
- php: ~8.2
- innmind/immutable: ~4.15|~5.0
Requires (Dev)
- innmind/black-box: ~5.0
- innmind/coding-standard: ~2.0
- phpunit/phpunit: ~10.2
- vimeo/psalm: ~5.6
Suggests
- innmind/black-box: For property based testing
Provides
Conflicts
- innmind/black-box: <5.0|~6.0
README
用于验证媒体类型的模型(遵循RFC6838)。
安装
composer install innmind/media-type
用法
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
如果值不正确,它将抛出异常。或者您可以使用 MediaType::maybe()
,这将返回一个 Innmind\Immutable\Maybe
实例。