承接 josantonius/mimetype 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

josantonius/mimetype

最新稳定版本:v2.0.3

Composer 安装命令:

composer require josantonius/mimetype

包简介

PHP library to get MIME types from extensions.

README 文档

README

Latest Stable Version License Total Downloads CI CodeCov PSR1 PSR4 PSR12

PHP library to get MIME types from extensions.

The original concept of my project, linking a single mimetype to a file extension, has been found to be insufficient in accurately reflecting the many-to-one relationships that exist in real-world use-cases. In practice, multiple file extensions often correspond to a single mimetype, rendering my existing design approach suboptimal.

Given these insights, I've decided to archive this repository. I recommend those interested to look at the approach taken by the repository patrickmccallum/mimetype-io. This project adopts a more nuanced perspective, effectively managing mimetypes by acknowledging the possibility of multiple extensions corresponding to a single mimetype. I believe this is a more promising approach for managing mimetypes moving forward.

Requirements

  • Operating System: Linux | Windows.

  • PHP versions: 8.0 | 8.1 | 8.2.

Installation

The preferred way to install this extension is through Composer.

To install PHP MimeType library, simply:

composer require josantonius/mime-type

The previous command will only install the necessary files, if you prefer to download the entire source code you can use:

composer require josantonius/mime-type --prefer-source

You can also clone the complete repository with Git:

git clone https://github.com/josantonius/php-mime-type.git

Available Classes

MimeType

Josantonius\MimeType\MimeType

Get array with all MIME types:

public function all(): array;

Get file extension from MIME type:

public function getExtension(string $mimeType): string|null;

Get MIME type from file extension:

public function getMime(string $extension): string|null;

MimeTypeCollection

Josantonius\MimeType\MimeTypeCollection

Get array with all MIME types:

public static function all(): array;

Get file extension from MIME type:

public static function getExtension(string $mimeType): string|null;

Get MIME type from file extension:

public static function getMime(string $extension): string|null;

Usage

Example of use for this library:

Get array with all MIME types

use Josantonius\MimeType\MimeType;

$mimeType = new MimeType();

$mimeType->all();
use Josantonius\MimeType\MimeTypeCollection;

MimeTypeCollection::all();

Result:

[
    [".123"]=> "application/vnd.lotus-1-2-3"
    [".3dml"]=> "text/vnd.in3d.3dml"
    [".3g2"]=> "video/3gpp2"
    [".3gp"]=> "video/3gpp"
    [".7z"]=> "application/x-7z-compressed"
    [".aab"]=> "application/x-authorware-bin"
    [".aac"]=> "audio/x-aac"
    [".aam"]=> "application/x-authorware-map"
    [".aas"]=> "application/x-authorware-seg"
    [".abw"]=> "application/x-abiword"
    (...)
]

Get file extension from MIME type

use Josantonius\MimeType\MimeType;

$mimeType = new MimeType();

$mimeType->getExtension('text/html'); // .html
use Josantonius\MimeType\MimeTypeCollection;

MimeTypeCollection::getExtension('application/zip'); // .zip

Get MIME type from file extension

use Josantonius\MimeType\MimeType;

$mimeType = new MimeType();

$mimeType->getMime('.tar'); // application/x-tar

// The dot can be omitted:

$mimeType->getMime('mp4'); // video/mp4
use Josantonius\MimeType\MimeTypeCollection;

MimeTypeCollection::getMime('.json'); // application/json

Tests

To run tests you just need composer and to execute the following:

git clone https://github.com/josantonius/php-mime-type.git
cd PHP-MimeType
composer install

Run unit tests with PHPUnit:

composer phpunit

Run code standard tests with PHPCS:

composer phpcs

Run PHP Mess Detector tests to detect inconsistencies in code style:

composer phpmd

Run all previous tests:

composer tests

TODO

  • Add new feature
  • Improve tests
  • Improve documentation
  • Improve English translation in the README file
  • Refactor code for disabled code style rules (see phpmd.xml and phpcs.xml)

Changelog

Detailed changes for each release are documented in the release notes.

Contribution

Please make sure to read the Contributing Guide, before making a pull request, start a discussion or report a issue.

Thanks to all contributors! ❤️

Sponsor

If this project helps you to reduce your development time, you can sponsor me to support my open source work 😊

License

This repository is licensed under the MIT License.

Copyright © 2016-2023, Josantonius

josantonius/mimetype 适用场景与选型建议

josantonius/mimetype 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.92k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2016 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「audio」 「mime」 「application」 「video」 「multipart」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 josantonius/mimetype 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 josantonius/mimetype 我们能提供哪些服务?
定制开发 / 二次开发

基于 josantonius/mimetype 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 3
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-20