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	"jsm" => "application/javascript",
33];
34
35foreach($additional_mime_maps as $ext => $mime) {
36	if (!isset($extensions[$ext])) {
37		$extensions[$ext] = $mime;
38	} else {
39		printf(STDERR, "Ignored exist mime type: $ext => $mime\n");
40	}
41}
42
43?>
44/*
45   +----------------------------------------------------------------------+
46   | PHP Version 7                                                        |
47   +----------------------------------------------------------------------+
48   | Copyright (c) 1997-2018 The PHP Group                                |
49   +----------------------------------------------------------------------+
50   | This source file is subject to version 3.01 of the PHP license,      |
51   | that is bundled with this package in the file LICENSE, and is        |
52   | available through the world-wide-web at the following url:           |
53   | http://www.php.net/license/3_01.txt                                  |
54   | If you did not receive a copy of the PHP license and are unable to   |
55   | obtain it through the world-wide-web, please send a note to          |
56   | license@php.net so we can mail you a copy immediately.               |
57   +----------------------------------------------------------------------+
58   | Author: Moriyoshi Koizumi <moriyoshi@php.net>                        |
59   +----------------------------------------------------------------------+
60*/
61
62/* This is a generated file. Rather than modifying it, please run
63 * "php generate_mime_type_map.php > mime_type_map.h" to regenerate the file. */
64
65#ifndef PHP_CLI_SERVER_MIME_TYPE_MAP_H
66#define PHP_CLI_SERVER_MIME_TYPE_MAP_H
67
68typedef struct php_cli_server_ext_mime_type_pair {
69	const char *ext;
70	const char *mime_type;
71} php_cli_server_ext_mime_type_pair;
72
73static const php_cli_server_ext_mime_type_pair mime_type_map[] = {
74<?php foreach ($extensions as $extension => $mime): ?>
75	{ "<?= addcslashes($extension, "\0..\37!@\@\177..\377") ?>", "<?= addcslashes($mime, "\0..\37!@\@\177..\377") ?>" },
76<?php endforeach ?>
77	{ NULL, NULL }
78};
79
80#endif /* PHP_CLI_SERVER_MIME_TYPE_MAP_H */
81
82/*
83 * Local variables:
84 * tab-width: 4
85 * c-basic-offset: 4
86 * End:
87 * vim600: noet sw=4 ts=4 fdm=marker
88 * vim<600: noet sw=4 ts=4
89 */
90