PHPackages                             componenta/mimetype-detector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. componenta/mimetype-detector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

componenta/mimetype-detector
============================

MIME type detection helpers for Componenta

v1.0.0(1mo ago)094MITPHPPHP ^8.4

Since Jun 16Pushed 1mo agoCompare

[ Source](https://github.com/componenta/mimetype-detector)[ Packagist](https://packagist.org/packages/componenta/mimetype-detector)[ RSS](/packages/componenta-mimetype-detector/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (4)

Componenta MIME Type Detector
=============================

[](#componenta-mime-type-detector)

MIME type and file-extension detection with value objects and a local MIME map.

Installation
------------

[](#installation)

```
composer require componenta/mimetype-detector
```

The package declares `Componenta\Detector\ConfigProvider` in `extra.componenta.config-providers`. When `componenta/composer-plugin` is installed, the provider is added to the generated provider list automatically.

Requirements
------------

[](#requirements)

- PHP 8.4+
- `fileinfo` extension
- PSR-7 stream interfaces from `psr/http-message`

Related Packages
----------------

[](#related-packages)

This package is standalone but requires the PHP `fileinfo` extension.

PackageWhy it may be used nearby`componenta/validation`MIME/file rules can use the detector for uploaded files.`componenta/http-responder`File responses can use MIME types for content headers.`componenta/image-converter`Media flows can detect a format before conversion.What It Provides
----------------

[](#what-it-provides)

- `MimeType`: parsed MIME type value object.
- `Ext`: normalized file extension value object.
- `MimeMapInterface` and `MimeMap`: MIME-to-extension and extension-to-MIME mapping.
- `FinfoDetector`: `fileinfo`-based detector for strings, streams, and files.
- `DetectorInterface`: combined contract for MIME type, extension, file MIME type, and file extension detection.
- Smaller contracts: `MimeTypeDetectorInterface`, `ExtensionDetectorInterface`, `FileMimeTypeDetectorInterface`, and `FileExtensionDetectorInterface`.
- `ConfigProvider`: registers the default detector and map services in Componenta applications.
- Typed exceptions for missing/unreadable files and invalid MIME types.

MIME Types
----------

[](#mime-types)

```
use Componenta\Detector\MimeType;

$mime = new MimeType('text/html; charset=utf-8');

$mime->value;      // text/html
$mime->type;       // text
$mime->subtype;    // html
$mime->charset;    // utf-8
$mime->isText();   // true
$mime->isWebSafe(); // true
```

Invalid MIME strings throw `InvalidMimeTypeException`.

Extensions
----------

[](#extensions)

```
use Componenta\Detector\Ext;

$ext = new Ext('.JPG');

$ext->value;    // jpg
$ext->withDot(); // .jpg
$ext->isImage(); // true
```

MIME Map
--------

[](#mime-map)

```
use Componenta\Detector\MimeMap;

$map = new MimeMap();

$map->getExtension('image/jpeg'); // jpg
$map->getMimeType('jpg');         // image/jpeg

$map->extend(['application/x-custom' => ['custom']]);
```

Detection
---------

[](#detection)

```
use Componenta\Detector\FinfoDetector;
use Componenta\Detector\MimeTypeDetectorInterface;

/** @var MimeTypeDetectorInterface $detector */
$detector = new FinfoDetector();

$detector->detectMimeType('plain text'); // text/plain
$detector->detectExtension('plain text'); // txt

$detector->detectFileMimeType('/path/to/file.txt');
$detector->detectFileExtension('/path/to/file.txt');
```

Pass `asObject: true` to return `MimeType` or `Ext` objects.

`FinfoDetector` reads up to 8192 bytes from files and streams. Seekable streams are rewound for detection and then restored to their previous position. Non-seekable streams are read from the current position, so callers should provide them at the correct offset.

File detection throws `FileNotFoundException`, `FileNotReadableException`, or `DetectorException` for I/O failures.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance91

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

43d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20490712?v=4)[Andrey Shelamkoff](/maintainers/Shelamkoff)[@Shelamkoff](https://github.com/Shelamkoff)

---

Top Contributors

[![Shelamkoff](https://avatars.githubusercontent.com/u/20490712?v=4)](https://github.com/Shelamkoff "Shelamkoff (1 commits)")

### Embed Badge

![Health badge](/badges/componenta-mimetype-detector/health.svg)

```
[![Health](https://phpackages.com/badges/componenta-mimetype-detector/health.svg)](https://phpackages.com/packages/componenta-mimetype-detector)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k543.5M2.7k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k48](/packages/neuron-core-neuron-ai)[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

345132.9M113](/packages/google-cloud-core)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[anthropic-ai/sdk

Anthropic PHP SDK

163583.3k20](/packages/anthropic-ai-sdk)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

36789.4k2](/packages/telnyx-telnyx-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
