1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
<?php /** * * This file is part of Aura for PHP. * * @license http://opensource.org/licenses/bsd-license.php BSD * */ namespace Aura\Accept\Media;
use Aura\Accept\AbstractNegotiator; use Aura\Accept\ValueFactory;
/** * * Represents a collection of `Accept` header values, sorted in quality * order. * * @package Aura.Accept * */ class MediaNegotiator extends AbstractNegotiator { /** * * The $_SERVER key to use when populating acceptable values. * * @var string * */ protected $server_key = 'HTTP_ACCEPT';
/** * * The type of value object to create using the ValueFactory. * * @var string * */ protected $value_type = 'media';
/** * * A map of file .extensions to media types. * * @var array * */ protected $types = array( '.aif' => 'audio/x-aiff', '.aifc' => 'audio/x-aiff', '.aiff' => 'audio/x-aiff', '.asf' => 'video/x-ms-asf', '.asr' => 'video/x-ms-asf', '.asx' => 'video/x-ms-asf', '.atom' => 'application/atom+xml', '.au' => 'audio/basic', '.avi' => 'video/x-msvideo', '.bas' => 'text/plain', '.bmp' => 'image/bmp', '.c' => 'text/plain', '.css' => 'text/css', '.csv' => 'text/csv', '.dtd' => 'application/xml-dtd', '.etx' => 'text/x-setext', '.flr' => 'x-world/x-vrml', '.gif' => 'image/gif', '.gz' => 'application/x-gzip', '.h' => 'text/plain', '.htm' => 'text/html', '.html' => 'text/html', '.ico' => 'image/x-icon', '.jfif' => 'image/pipeg', '.jpe' => 'image/jpeg', '.jpeg' => 'image/jpeg', '.jpg' => 'image/jpeg', '.js' => 'text/javascript', '.json' => 'application/json', '.lsf' => 'video/x-la-asf', '.lsx' => 'video/x-la-asf', '.m3u' => 'audio/x-mpegurl', '.mid' => 'audio/mid', '.mov' => 'video/quicktime', '.movie' => 'video/x-sgi-movie', '.mp2' => 'video/mpeg', '.mp3' => 'audio/mpeg', '.mpa' => 'video/mpeg', '.mpe' => 'video/mpeg', '.mpeg' => 'video/mpeg', '.mpg' => 'video/mpeg', '.mpv2' => 'video/mpeg', '.ogg' => 'application/ogg', '.pbm' => 'image/x-portable-bitmap', '.pdf' => 'application/pdf', '.pgm' => 'image/x-portable-graymap', '.png' => 'image/png', '.pnm' => 'image/x-portable-anymap', '.ppm' => 'image/x-portable-pixmap', '.ps' => 'application/postscript', '.qt' => 'video/quicktime', '.ra' => 'audio/x-pn-realaudio', '.ram' => 'audio/x-pn-realaudio', '.ras' => 'image/x-cmu-raster', '.rdf' => 'application/rdf+xml', '.rgb' => 'image/x-rgb', '.rmi' => 'audio/mid', '.rss' => 'application/rss+xml', '.rss2' => 'application/rss+xml', '.rtf' => 'application/rtf', '.snd' => 'audio/basic', '.svg' => 'image/svg+xml', '.text' => 'text/plain', '.tif' => 'image/tiff', '.tiff' => 'image/tiff', '.tsv' => 'text/plain', '.txt' => 'text/plain', '.vcf' => 'text/x-vcard', '.vrml' => 'x-world/x-vrml', '.wav' => 'audio/x-wav', '.wrl' => 'x-world/x-vrml', '.wrz' => 'x-world/x-vrml', '.xaf' => 'x-world/x-vrml', '.xbm' => 'image/x-xbitmap', '.xht' => 'application/xhtml+xml', '.xhtml' => 'application/xhtml+xml', '.xml' => 'application/xml', '.xof' => 'x-world/x-vrml', '.xpm' => 'image/x-xpixmap', '.xwd' => 'image/x-xwindowdump', '.zip' => 'application/zip', );
/** * * Constructor. * * @param ValueFactory $value_factory A factory for value objects. * * @param array $server A copy of $_SERVER for finding acceptable values. * * @param array $types Additional extensions to media type mappings. * */ public function __construct( ValueFactory $value_factory, array $server = array(), array $types = array() ) { // parent construction parent::__construct($value_factory, $server);
// merge the media type mappings $this->types = array_merge($this->types, $types);
// override the media type if a file extension exists in the path $request_uri = isset($server['REQUEST_URI']) ? $server['REQUEST_URI'] : null; $path = parse_url('http://example.com/' . $request_uri, PHP_URL_PATH); $name = basename((string) $path); $ext = strrchr($name, '.'); if ($ext && isset($this->types[$ext])) { $this->set($this->types[$ext]); } } }
|