Apache MIME Types

Overview

Apache MIME Types

Parses Apache MIME Types files and provides a simple interface to find extensions by type and type by extension.

Build Status

Features

  • Bundles mime.types from the Apache HTTP Project. (see here)
  • Bundles a JSON representation of Apache mime.types.
  • Provides an interface for reading either flat Apache HTTP mime.types or a JSON representation.

Requirements

  • PHP 5.3.3+

Installation

Through Composer as dflydev/apache-mime-types.

Usage

Parser

Parses Apache MIME Types in the format of mime.types found here.

<?php
$parser = new Dflydev\ApacheMimeTypes\Parser;

$map = $parser->parse('/path/to/mime.types');

The return value from parse is an array mapping types to an array of extensions.

<?php
array(
    'text/html' => array('html', 'htm'),
);

PhpRepository

A repository backed by static PHP arrays.

<?php
$repository = new Dflydev\ApacheMimeTypes\PhpRepository;

$type = $repository->findType('html');
$extensions = $repository->findExtensions('text/html');

var_dump($type);
var_dump($extensions);

//
// Result
//
// string(9) "text/html"
// array(2) {
//   [0]=>
//   string(4) "html"
//   [1]=>
//   string(3) "htm"
// }
//

JsonRepository

A repository backed by a JSON map of type to extensions.

{
    "text/html": ["html", "htm"]
}

To use the embedded JSON:

<?php
$repository = new Dflydev\ApacheMimeTypes\JsonRepository;

$type = $repository->findType('html');
$extensions = $repository->findExtensions('text/html');

var_dump($type);
var_dump($extensions);

//
// Result
//
// string(9) "text/html"
// array(2) {
//   [0]=>
//   string(4) "html"
//   [1]=>
//   string(3) "htm"
// }
//

To specify a specific JSON mapping:

<?php
$repository = new Dflydev\ApacheMimeTypes\JsonRepository('/path/to/mime.types.json');

FlatRepository

A repository backed by Apache MIME Types formatted mime.types. To use the embedded mime.types:

<?php
$repository = new Dflydev\ApacheMimeTypes\FlatRepository;

$type = $repository->findType('html');
$extensions = $repository->findExtensions('text/html');

var_dump($type);
var_dump($extensions);

//
// Result
//
// string(9) "text/html"
// array(2) {
//   [0]=>
//   string(4) "html"
//   [1]=>
//   string(3) "htm"
// }
//

To specify a specific mime.types mapping:

<?php
$repository = new Dflydev\ApacheMimeTypes\FlatRepository('/path/to/mime.types');

License

MIT, see LICENSE.

Community

If you have questions or want to help out, join us in the #dflydev channel on irc.freenode.net.

Not Invented Here

This project is based heavily on skyzyx/mimetypes. The major difference is that skyzyx/mimetypes is focussed on creating JSON files from Apache mime.types rather than providing a way to interact with Apache MIME Types as a data source.

Comments
  • Add php mime type

    Add php mime type

    While PHP files don't have an official mime type adding these in will allow the package to identify various php extensions. The type used is one prefixed with text since PHP files should be human readable, this allows someone to identify a PHP file as plain text.

    It's particularly useful to detect and then display the contents of a PHP file in a web app.

    opened by mallardduck 10
  • MIME parsing updates

    MIME parsing updates

    Some MIME types that include a semicolon (;) do not parse correctly. This fixes that parsing error and adds a findExtension method to look up a correct extension based on MIME type. The phpRepository class is updated as a result.

    opened by benallfree 5
  • Restructure tests and add PHPUnit to package dependencies

    Restructure tests and add PHPUnit to package dependencies

    This change updates the way the tests are structured to use PSR-4 style autoloading. The changes here will also help keep the package testable in the future as PHP7+ is taking over fast. So making sure the latest PHPUnit is supported will be important.

    opened by mallardduck 0
  • MIME parsing updates

    MIME parsing updates

    Some MIME types that include a semicolon (;) do not parse correctly. This fixes that parsing error and adds a findExtension method to look up a correct extension based on MIME type. The phpRepository class is updated as a result.

    opened by benallfree 0
  • No LICENSE, no copyright

    No LICENSE, no copyright

    https://github.com/dflydev/dflydev-apache-mime-types#license says "MIT, see LICENSE" but the LICENSE is nowhere to be found.

    Also copyright statement is missing.

    opened by onlyjob 0
Owner
dflydev
I'm Dragonfly Development (aka dflydev), a technology strategy consultancy created by Beau Simensen (@simensen). I also host Beau's public open-source projects.
dflydev
The Hoa\Mime library.

Hoa is a modular, extensible and structured set of PHP libraries. Moreover, Hoa aims at being a bridge between industrial and research worlds. Hoa\Mim

Hoa 100 Nov 20, 2022
📧 Handy email creation and transfer library for PHP with both text and MIME-compliant support.

?? Handy email creation and transfer library for PHP with both text and MIME-compliant support.

Nette Foundation 401 Dec 22, 2022
PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.

P H I N G Thank you for using PHING! PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant. You can do anything wit

The Phing Project 1.1k Dec 22, 2022
PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.

P H I N G Thank you for using PHING! PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant. You can do anything wit

The Phing Project 1.1k Jan 7, 2023
A TYPO3 extension that integrates the Apache Solr search server with TYPO3 CMS. dkd Internet Service GmbH is developing the extension. Community contributions are welcome. See CONTRIBUTING.md for details.

Apache Solr for TYPO3 CMS A TYPO3 extension that integrates the Apache Solr enterprise search server with TYPO3 CMS. The extension has initially been

Apache Solr for TYPO3 126 Dec 7, 2022
PHP implementation for reading and writing Apache Parquet files/streams

php-parquet This is the first parquet file format reader/writer implementation in PHP, based on the Thrift sources provided by the Apache Foundation.

null 17 Oct 25, 2022
Apache OpenWhisk is an open source serverless cloud platform

OpenWhisk OpenWhisk is a serverless functions platform for building cloud applications. OpenWhisk offers a rich programming model for creating serverl

The Apache Software Foundation 5.9k Jan 8, 2023
Brew PHP switcher is a simple shell script to switch your apache and CLI quickly between major versions of PHP

Brew PHP switcher is a simple shell script to switch your apache and CLI quickly between major versions of PHP. If you support multiple products/projects that are built using either brand new or old legacy PHP functionality. For users of Homebrew (or brew for short) currently only.

Phil Cook 872 Dec 22, 2022
Middleware to generate access logs for each request using the Apache's access log format

Middleware to generate access logs for each request using the Apache's access log format. This middleware requires a Psr log implementation, for example monolog.

Middlewares 20 Jun 23, 2022
Modello base con tutto il docker configurato per php7.4, mariadb, vue3, apache...con esempi di component e chiamate rest interne

Applicazione base per utilizzare laravel con docker, php7.4, apache, mariadb10, vue3 Semplice installazione corredate di rotte web e api di base, 3 co

null 0 Jul 14, 2022
Docker with Apache, MySql, PhpMyAdmin and Php

docker-lamp Docker example with Apache, MySql 8.0, PhpMyAdmin and Php You can use MariaDB 10.1 if you checkout to the tag mariadb-10.1 - contribution

Joel Cavat 360 Dec 3, 2022
cybercog 996 Dec 28, 2022
Maps Laravel Eloquent models to Elasticsearch types

Elasticquent Elasticsearch for Eloquent Laravel Models Elasticquent makes working with Elasticsearch and Eloquent models easier by mapping them to Ela

Elasticquent 1.3k Jan 4, 2023
Missing data types for PHP. Highly extendable.

Neverending data validation can be exhausting. Either you have to validate your data over and over again in every function you use it, or you have to rely it has already been validated somewhere else and risk potential problems.

SmartEmailing 82 Nov 11, 2022
Pods is a development framework for creating, extending, managing, and deploying customized content types in WordPress.

Pods Framework Pods is a development framework for creating, extending, managing, and deploying customized content types in WordPress. Description Che

Pods Foundation, Inc 982 Jan 4, 2023
Next generation phpDoc parser with support for intersection types and generics.

PHPDoc-Parser for PHPStan PHPStan Next generation phpDoc parser with support for intersection types and generics. Code of Conduct This project adheres

PHPStan 909 Dec 29, 2022
Add subtitles into your WordPress posts, pages, custom post types, and themes. No coding required.

Add subtitles into your WordPress posts, pages, custom post types, and themes. No coding required. Simply activate Subtitles and you're ready to go.

We Cobble 117 Dec 31, 2022
A PHP Class for creating Wordpress Custom Post Types easily

N.B I've released an updated version of the project to a new repository, PostTypes. WP Custom Post Type Class v1.4 A single class to help you build mo

Joe Grainger 412 Nov 25, 2022