1#!/usr/bin/env php 2<?php 3 4// Check if we are being given a mime.types file or if we should use the 5// default URL. 6$source = count($_SERVER['argv']) > 1 ? $_SERVER['argv'][1] : 'https://raw.githubusercontent.com/apache/httpd/trunk/docs/conf/mime.types'; 7 8// See if we can actually load it. 9$types = @file($source); 10if ($types === false) { 11 fprintf(STDERR, "Error: unable to read $source\n"); 12 exit(1); 13} 14 15// Remove comments and flip into an extensions array. 16$extensions = []; 17array_walk($types, function ($line) use (&$extensions) { 18 $line = trim($line); 19 if ($line && $line[0] != '#') { 20 $fields = preg_split('/\s+/', $line); 21 if (count($fields) > 1) { 22 $mime = array_shift($fields); 23 foreach ($fields as $extension) { 24 $extensions[$extension] = $mime; 25 } 26 } 27 } 28}); 29 30$additional_mime_maps = [ 31 "map" => "application/json", // from commit: a0d62f08ae8cbebc88e5c92e08fca8d0cdc7309d 32]; 33 34foreach($additional_mime_maps as $ext => $mime) { 35 if (!isset($extensions[$ext])) { 36 $extensions[$ext] = $mime; 37 } else { 38 printf(STDERR, "Ignored exist mime type: $ext => $mime\n"); 39 } 40} 41 42?> 43/* 44 +----------------------------------------------------------------------+ 45 | PHP Version 7 | 46 +----------------------------------------------------------------------+ 47 | Copyright (c) 1997-2018 The PHP Group | 48 +----------------------------------------------------------------------+ 49 | This source file is subject to version 3.01 of the PHP license, | 50 | that is bundled with this package in the file LICENSE, and is | 51 | available through the world-wide-web at the following url: | 52 | http://www.php.net/license/3_01.txt | 53 | If you did not receive a copy of the PHP license and are unable to | 54 | obtain it through the world-wide-web, please send a note to | 55 | license@php.net so we can mail you a copy immediately. | 56 +----------------------------------------------------------------------+ 57 | Author: Moriyoshi Koizumi <moriyoshi@php.net> | 58 +----------------------------------------------------------------------+ 59*/ 60 61/* This is a generated file. Rather than modifying it, please run 62 * "php generate_mime_type_map.php > mime_type_map.h" to regenerate the file. */ 63 64#ifndef PHP_CLI_SERVER_MIME_TYPE_MAP_H 65#define PHP_CLI_SERVER_MIME_TYPE_MAP_H 66 67typedef struct php_cli_server_ext_mime_type_pair { 68 const char *ext; 69 const char *mime_type; 70} php_cli_server_ext_mime_type_pair; 71 72static php_cli_server_ext_mime_type_pair mime_type_map[] = { 73<?php foreach ($extensions as $extension => $mime): ?> 74 { "<?= addcslashes($extension, "\0..\37!@\@\177..\377") ?>", "<?= addcslashes($mime, "\0..\37!@\@\177..\377") ?>" }, 75<?php endforeach ?> 76 { NULL, NULL } 77}; 78 79#endif /* PHP_CLI_SERVER_MIME_TYPE_MAP_H */ 80 81/* 82 * Local variables: 83 * tab-width: 4 84 * c-basic-offset: 4 85 * End: 86 * vim600: noet sw=4 ts=4 fdm=marker 87 * vim<600: noet sw=4 ts=4 88 */ 89