adrienrn/php-mimetyper
A lightweight PHP library for MIME type mapping. Look up MIME types by file extension and extensions by MIME type through a simple API, useful for uploads, validation, and content headers without relying on file inspection.
Architecture fit. adrienrn/php-mimetyper is a narrow, computation-only library: it maps MIME types to extensions and back, using a bundled snapshot of the jshttp/mime-db dataset (the same corpus behind Node's mime-db/mime-types). It has no database, network, cache, or framework coupling, so it slots into Laravel as a supporting utility rather than an architectural dependency. The natural placement is behind a small application service (e.g., MimeTypeResolver or FileTypeService) registered as a container singleton, keeping the third-party namespace out of controllers, jobs, and Blade templates.
Integration feasibility. MIT-licensed, Composer-installable, PSR-4, Symfony-compatible — which, given Laravel's Symfony inheritance, implies Laravel compatibility with low friction. The integration surface is a handful of method calls. The real feasibility question is not "does it work" but "does it overlap with what we already have." Laravel's mimes/mimetypes validation rules and Illuminate\Http\Testing\MimeType delegate to symfony/mime. Introducing this package for validation would be duplicate logic; introducing it for extension/label resolution outside validation (download filenames, icon selection, content negotiation, storage metadata) is additive and defensible.
Technical risk. Two distinct risks, with very different profiles:
Key questions.
composer.json declare, and do they intersect with our current and next-two-quarter upgrade targets?mime-db snapshot bundled at release or generated at install? What is the expected refresh cadence, and how stale is it today?getExtensions(), getMimeTypes(), first-match vs. all-match semantics)? Extension ordering matters for filename generation and must be deterministic.symfony/mime on aliases, vendor-prefixed types (application/vnd.*), and multi-extension types?Stack fit. Composer dependency wrapped in a first-party adapter class implementing a first-party interface. Define MimeTypeResolverInterface in our domain, implement it with adrienrn/php-mimetyper, and bind it in a service provider. Every call site depends on the interface, never on the package namespace. This single decision converts the dependency from "architectural" back to "implementation detail" and makes the exit cost near-zero.
Migration path. Do not rip out existing logic. Start with an adapter that exposes the same behavior as whatever we currently do (likely symfony/mime or ad-hoc pathinfo()/finfo calls). In staging, dual-write: compute results from both the old path and the new adapter and log divergences to a comparison channel for one full release cycle. Because both ultimately derive from comparable mime databases, divergence should be concentrated in edge cases — this diff log is where the real knowledge is captured.
Compatibility. Pin an exact version in composer.json ("adrienrn/php-mimetyper": "x.y.z") rather than a caret range, given the low release velocity. Confirm the declared PHP constraint against the CI matrix. Explicitly keep symfony/mime in place for validation rules and finfo/fileinfo for content sniffing — this package is for naming and classification, not for trusting an uploaded file's true type. That boundary should be written down, not assumed.
Sequencing.
Maintenance. Runtime maintenance is near-zero: no configuration, no migrations, no external services. The maintenance burden is upstream surveillance — a quarterly check of commits, issues, and mime-db freshness. Because the library is data-driven, the only genuine ongoing need is occasionally refreshing the mapping snapshot, which is a fork-level task if upstream is dormant.
Support. No vendor, no SLA, no commercial escalation path. The internal support model must be: one named owner, a wiki page describing the adapter boundary, and a documented "replace in under a day" procedure. Given the small surface area, this is a realistic bar — unlike a low-star package that owns state, queues, or protocols.
Scaling. Irrelevant at the scaling layer. Lookups are in-memory hash access with no I/O and no state, so it is horizontal-scaling-neutral and safe inside long-running workers (Octane, queue workers) provided the map is immutable — which it is. The only performance note is memory: if the full map is large, verify it isn't reloaded per resolution call; a lazy-loaded singleton is the standard remedy.
Failure modes.
symfony/mime. Inconsistent labeling between validation and presentation. Mitigation: diff logging during rollout, plus a documented decision on which library owns which concern.Ramp-up. Effectively trivial for any mid-level Laravel engineer — half a day to read the API and write the adapter and tests. The actual effort in this initiative is not learning php-mimetyper; it is the organizational work of consolidating scattered MIME-handling logic into one owned service. Budget accordingly: the package is the easy part, the refactor is the deliverable.
TPM read. This is a low-cost, low-blast-radius "buy" with a credible "build-replaceable" exit. The opportunity score is reasonable: it removes a small amount of duplicated file-type logic and aligns our mapping with a cross-language standard. It should not be adopted as a critical-path or security-relevant dependency, and it should not be introduced to replace symfony/mime inside validation. Adopt behind an adapter, flag it, log divergences, and revisit at the next framework upgrade.
How can I help you explore Laravel packages today?