<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Mime;
use Symfony\Component\Mime\Exception\LogicException;
/**
* Manages MIME types and file extensions.
*
* For MIME type guessing, you can register custom guessers
* by calling the registerGuesser() method.
* Custom guessers are always called before any default ones:
*
* $guesser = new MimeTypes();
* $guesser->registerGuesser(new MyCustomMimeTypeGuesser());
*
* If you want to change the order of the default guessers, just re-register your
* preferred one as a custom one. The last registered guesser is preferred over
* previously registered ones.
*
* Re-registering a built-in guesser also allows you to configure it:
*
* $guesser = new MimeTypes();
* $guesser->registerGuesser(new FileinfoMimeTypeGuesser('/path/to/magic/file'));
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class MimeTypes implements MimeTypesInterface
{
private $extensions = [];
private $mimeTypes = [];
/**
* @var MimeTypeGuesserInterface[]
*/
private $guessers = [];
private static $default;
public function __construct(array $map = [])
{
foreach ($map as $mimeType => $extensions) {
$this->extensions[$mimeType] = $extensions;
foreach ($extensions as $extension) {
$this->mimeTypes[$extension][] = $mimeType;
}
}
$this->registerGuesser(new FileBinaryMimeTypeGuesser());
$this->registerGuesser(new FileinfoMimeTypeGuesser());
}
public static function setDefault(self $default)
{
self::$default = $default;
}
public static function getDefault(): self
{
return self::$default ?? self::$default = new self();
}
/**
* Registers a MIME type guesser.
*
* The last registered guesser has precedence over the other ones.
*/
public function registerGuesser(MimeTypeGuesserInterface $guesser)
{
array_unshift($this->guessers, $guesser);
}
/**
* {@inheritdoc}
*/
public function getExtensions(string $mimeType): array
{
if ($this->extensions) {
$extensions = $this->extensions[$mimeType] ?? $this->extensions[$lcMimeType = strtolower($mimeType)] ?? null;
}
return $extensions ?? self::$map[$mimeType] ?? self::$map[$lcMimeType ?? strtolower($mimeType)] ?? [];
}
/**
* {@inheritdoc}
*/
public function getMimeTypes(string $ext): array
{
if ($this->mimeTypes) {
$mimeTypes = $this->mimeTypes[$ext] ?? $this->mimeTypes[$lcExt = strtolower($ext)] ?? null;
}
return $mimeTypes ?? self::$reverseMap[$ext] ?? self::$reverseMap[$lcExt ?? strtolower($ext)] ?? [];
}
/**
* {@inheritdoc}
*/
public function isGuesserSupported(): bool
{
foreach ($this->guessers as $guesser) {
if ($guesser->isGuesserSupported()) {
return true;
}
}
return false;
}
/**
* {@inheritdoc}
*
* The file is passed to each registered MIME type guesser in reverse order
* of their registration (last registered is queried first). Once a guesser
* returns a value that is not null, this method terminates and returns the
* value.
*/
public function guessMimeType(string $path): ?string
{
foreach ($this->guessers as $guesser) {
if (!$guesser->isGuesserSupported()) {
continue;
}
if (null !== $mimeType = $guesser->guessMimeType($path)) {
return $mimeType;
}
}
if (!$this->isGuesserSupported()) {
throw new LogicException('Unable to guess the MIME type as no guessers are available (have you enabled the php_fileinfo extension?).');
}
return null;
}
/**
* A map of MIME types and their default extensions.
*
* Updated from upstream on 2019-01-16
*
* @see Resources/bin/update_mime_types.php
*/
private static $map = [
'application/acrobat' => ['pdf'],
'application/andrew-inset' => ['ez'],
'application/annodex' => ['anx'],
'application/applixware' => ['aw'],
'application/atom+xml' => ['atom'],
'application/atomcat+xml' => ['atomcat'],
'application/atomdeleted+xml' => ['atomdeleted'],
'application/atomsvc+xml' => ['atomsvc'],
'application/atsc-dwd+xml' => ['dwd'],
'application/atsc-held+xml' => ['held'],
'application/atsc-rsat+xml' => ['rsat'],
'application/bdoc' => ['bdoc'],
'application/calendar+xml' => ['xcs'],
'application/ccxml+xml' => ['ccxml'],
'application/cdfx+xml' => ['cdfx'],
'application/cdmi-capability' => ['cdmia'],
'application/cdmi-container' => ['cdmic'],
'application/cdmi-domain' => ['cdmid'],
'application/cdmi-object' => ['cdmio'],
'application/cdmi-queue' => ['cdmiq'],
'application/cdr' => ['cdr'],
'application/coreldraw' => ['cdr'],
'application/csv' => ['csv'],
'application/cu-seeme' => ['cu'],
'application/dash+xml' => ['mpd'],
'application/davmount+xml' => ['davmount'],
'application/dbase' => ['dbf'],
'application/dbf' => ['dbf'],
'application/dicom' => ['dcm'],
'application/docbook+xml' => ['dbk', 'docbook'],
'application/dssc+der' => ['dssc'],
'application/dssc+xml' => ['xdssc'],
'application/ecmascript' => ['ecma', 'es'],
'application/emf' => ['emf'],
'application/emma+xml' => ['emma'],
'application/emotionml+xml' => ['emotionml'],
'application/epub+zip' => ['epub'],
'application/exi' => ['exi'],
'application/fdt+xml' => ['fdt'],
'application/font-tdpfr' => ['pfr'],
'application/font-woff' => ['woff'],
'application/futuresplash' => ['swf', 'spl'],
'application/geo+json' => ['geojson', 'geo.json'],
'application/gml+xml' => ['gml'],
'application/gnunet-directory' => ['gnd'],
'application/gpx' => ['gpx'],
'application/gpx+xml' => ['gpx'],
'application/gxf' => ['gxf'],
'application/gzip' => ['gz'],
'application/hjson' => ['hjson'],
'application/hyperstudio' => ['stk'],
'application/ico' => ['ico'],
'application/ics' => ['vcs', 'ics'],
'application/illustrator' => ['ai'],
'application/inkml+xml' => ['ink', 'inkml'],
'application/ipfix' => ['ipfix'],
'application/its+xml' => ['its'],
'application/java' => ['class'],
'application/java-archive' => ['jar', 'war', 'ear'],
'application/java-byte-code' => ['class'],
'application/java-serialized-object' => ['ser'],
'application/java-vm' => ['class'],
'application/javascript' => ['js', 'mjs', 'jsm'],
'application/jrd+json' => ['jrd'],
'application/json' => ['json', 'map'],
'application/json-patch+json' => ['json-patch'],
'application/json5' => ['json5'],
'application/jsonml+json' => ['jsonml'],
'application/ld+json' => ['jsonld'],
'application/lgr+xml' => ['lgr'],
'application/lost+xml' => ['lostxml'],
'application/lotus123' => ['123', 'wk1', 'wk3', 'wk4', 'wks'],
'application/m3u' => ['m3u', 'm3u8', 'vlc'],
'application/mac-binhex40' => ['hqx'],
'application/mac-compactpro' => ['cpt'],
'application/mads+xml' => ['mads'],
'application/manifest+json' => ['webmanifest'],
'application/marc' => ['mrc'],
'application/marcxml+xml' => ['mrcx'],
没有合适的资源?快使用搜索试试~ 我知道了~
PHP实例开发源码-Symfony web应用php框架.zip
共2000个文件
php:3060个
json:1334个
md:209个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 189 浏览量
2022-11-21
17:11:21
上传
评论
收藏 8.17MB ZIP 举报
温馨提示
PHP实例开发源码—Symfony web应用php框架.zip PHP实例开发源码—Symfony web应用php框架.zip PHP实例开发源码—Symfony web应用php框架.zip
资源推荐
资源详情
资源评论
收起资源包目录
PHP实例开发源码-Symfony web应用php框架.zip (2000个子文件)
favicon.png.base64 1KB
CODEOWNERS 3KB
compile 371B
main.css 29KB
exception.css 14KB
htmlDescriptor.css 3KB
exception_full.css 3KB
error.css 275B
local.css 273B
phpunit.xml.dist 4KB
.php_cs.dist 2KB
phpunit.xml.dist 1KB
phpunit.xml.dist 892B
phpunit.xml.dist 891B
phpunit.xml.dist 881B
.editorconfig 286B
hiddeninput.exe 9KB
.gitignore 121B
.gitignore 34B
.gitignore 34B
.gitignore 34B
.gitignore 34B
.gitignore 34B
.gitignore 34B
.gitignore 34B
.gitignore 34B
time.js 13KB
exception.js 13KB
htmlDescriptor.js 354B
ff_Adlm.json 64KB
km.json 53KB
dz.json 51KB
my.json 50KB
ml.json 49KB
si.json 49KB
ka.json 48KB
ta.json 47KB
as.json 47KB
meta.json 46KB
kn.json 46KB
bn.json 45KB
dz.json 45KB
th.json 45KB
lo.json 45KB
te.json 45KB
gu.json 44KB
ka.json 44KB
hi.json 44KB
ta.json 43KB
or.json 43KB
ne.json 43KB
ff_Adlm.json 43KB
uk.json 42KB
my.json 42KB
kn.json 42KB
pa.json 42KB
te.json 42KB
si.json 42KB
bn.json 42KB
ne.json 42KB
ml.json 42KB
km.json 41KB
mr.json 41KB
or.json 40KB
hi.json 40KB
th.json 40KB
as.json 40KB
gu.json 40KB
hy.json 39KB
mr.json 39KB
bg.json 39KB
lo.json 38KB
ky.json 38KB
mk.json 38KB
sr_Cyrl_BA.json 38KB
am.json 38KB
pa.json 38KB
el.json 37KB
be.json 37KB
kk.json 37KB
kk.json 36KB
sr.json 36KB
bs_Cyrl.json 36KB
uk.json 35KB
hy.json 34KB
ar.json 34KB
be.json 34KB
ug.json 34KB
ru.json 34KB
tt.json 34KB
ar.json 33KB
ks.json 33KB
mk.json 33KB
el.json 33KB
sr.json 33KB
ce.json 33KB
ru.json 33KB
bs_Cyrl.json 33KB
ug.json 33KB
bg.json 33KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
毕业_设计
- 粉丝: 1921
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功