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