From 5808715df2d44ced5b760345ab64a861585bbd4e Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 30 May 2011 16:12:18 +0200 Subject: [PATCH 001/196] [Translation] Add Qt Translation component with tests --- .../Loader/QtTranslationsLoader.php | 83 +++++++++++++++++++ .../Loader/QtTranslationsLoaderTest.php | 29 +++++++ .../Translation/fixtures/resources.ts | 10 +++ 3 files changed, 122 insertions(+) create mode 100644 src/Symfony/Component/Translation/Loader/QtTranslationsLoader.php create mode 100644 tests/Symfony/Tests/Component/Translation/Loader/QtTranslationsLoaderTest.php create mode 100644 tests/Symfony/Tests/Component/Translation/fixtures/resources.ts diff --git a/src/Symfony/Component/Translation/Loader/QtTranslationsLoader.php b/src/Symfony/Component/Translation/Loader/QtTranslationsLoader.php new file mode 100644 index 0000000000000..ba4a05681c14e --- /dev/null +++ b/src/Symfony/Component/Translation/Loader/QtTranslationsLoader.php @@ -0,0 +1,83 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Translation\MessageCatalogue; + +/** + * QtTranslationsLoader loads translations from QT Translations XML files. + * + * @author Benjamin Eberlei + * + * @api + */ +class QtTranslationsLoader implements LoaderInterface +{ + /** + * {@inheritdoc} + * + * @api + */ + public function load($resource, $locale, $domain = 'messages') + { + $dom = new \DOMDocument(); + $current = libxml_use_internal_errors(true); + if (!@$dom->load($resource, LIBXML_COMPACT)) { + throw new \Exception(implode("\n", $this->getXmlErrors())); + } + + $xpath = new \DOMXPath($dom); + $nodes = $xpath->evaluate('//TS/context/name[text()="'.$domain.'"]'); + + $catalogue = new MessageCatalogue($locale); + if ($nodes->length == 1) { + $translations = $nodes->item(0)->nextSibling->parentNode->parentNode->getElementsByTagName('message'); + foreach ($translations as $translation) { + $catalogue->set( + (string) $translation->getElementsByTagName('source')->item(0)->nodeValue, + (string) $translation->getElementsByTagName('translation')->item(0)->nodeValue, + $domain + ); + $translation = $translation->nextSibling; + } + $catalogue->addResource(new FileResource($resource)); + } + + return $catalogue; + } + + /** + * Returns the XML errors of the internal XML parser + * + * @return array An array of errors + */ + private function getXmlErrors() + { + $errors = array(); + foreach (libxml_get_errors() as $error) { + $errors[] = sprintf('[%s %s] %s (in %s - line %d, column %d)', + LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR', + $error->code, + trim($error->message), + $error->file ? $error->file : 'n/a', + $error->line, + $error->column + ); + } + + libxml_clear_errors(); + libxml_use_internal_errors(false); + + return $errors; + } +} \ No newline at end of file diff --git a/tests/Symfony/Tests/Component/Translation/Loader/QtTranslationsLoaderTest.php b/tests/Symfony/Tests/Component/Translation/Loader/QtTranslationsLoaderTest.php new file mode 100644 index 0000000000000..a3375ce444dbf --- /dev/null +++ b/tests/Symfony/Tests/Component/Translation/Loader/QtTranslationsLoaderTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\Translation\Loader; + +use Symfony\Component\Translation\Loader\QtTranslationsLoader; +use Symfony\Component\Config\Resource\FileResource; + +class QtTranslationsLoaderTest extends \PHPUnit_Framework_TestCase +{ + public function testLoad() + { + $loader = new QtTranslationsLoader(); + $resource = __DIR__.'/../fixtures/resources.ts'; + $catalogue = $loader->load($resource, 'en', 'resources'); + + $this->assertEquals(array('foo' => 'bar'), $catalogue->all('resources')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } +} diff --git a/tests/Symfony/Tests/Component/Translation/fixtures/resources.ts b/tests/Symfony/Tests/Component/Translation/fixtures/resources.ts new file mode 100644 index 0000000000000..1e03f03db3692 --- /dev/null +++ b/tests/Symfony/Tests/Component/Translation/fixtures/resources.ts @@ -0,0 +1,10 @@ + + + + resources + + foo + bar + + + From 6bf43a1878ab116a1893196576eabac51ba70776 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 30 May 2011 16:50:49 +0200 Subject: [PATCH 002/196] [Translation] Add .ts as file extension to search for Qt Translation files. --- .../Bundle/FrameworkBundle/Resources/config/translation.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml index f382ed06dbc08..f05335b453529 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml @@ -11,6 +11,7 @@ Symfony\Component\Translation\Loader\PhpFileLoader Symfony\Component\Translation\Loader\YamlFileLoader Symfony\Component\Translation\Loader\XliffFileLoader + Symfony\Component\Translation\Loader\QtTranslationsLoader @@ -42,5 +43,9 @@ + + + + From dd20f0145aa24d543ca72d300ffbdc10d0fe7b0b Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Tue, 31 May 2011 12:09:50 -0700 Subject: [PATCH 003/196] Fixed assets:install to use a relative path instead of an absolute --- .../Command/AssetsInstallCommand.php | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 1aeb152161471..83a17d95f9681 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -74,14 +74,16 @@ protected function execute(InputInterface $input, OutputInterface $output) foreach ($this->container->get('kernel')->getBundles() as $bundle) { if (is_dir($originDir = $bundle->getPath().'/Resources/public')) { - $targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($bundle->getName())); + $bundlesDir = $input->getArgument('target').'/bundles/'; + $targetDir = $bundlesDir.preg_replace('/bundle$/', '', strtolower($bundle->getName())); $output->writeln(sprintf('Installing assets for %s into %s', $bundle->getNamespace(), $targetDir)); $filesystem->remove($targetDir); if ($input->getOption('symlink')) { - $filesystem->symlink($originDir, $targetDir); + $relativeOriginDir = $this->makePathRelative($originDir, realpath($bundlesDir)); + $filesystem->symlink($relativeOriginDir, $targetDir); } else { $filesystem->mkdir($targetDir, 0777); $filesystem->mirror($originDir, $targetDir); @@ -89,4 +91,31 @@ protected function execute(InputInterface $input, OutputInterface $output) } } } + + /** + * Given an existing path, convert it to a path relative to a given starting path + * + * @var string Absolute path of target + * @var string Absolute path where traversal begins + * @return string Path of target relative to starting path + */ + protected function makePathRelative($endPath, $startPath) + { + // Find for which character the the common path stops + $offset = 0; + while ($startPath[$offset] === $endPath[$offset]) { + $offset++; + } + + // Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels) + $depth = substr_count(substr($startPath, $offset), DIRECTORY_SEPARATOR) + 1; + + // Repeated "../" for each level need to reach the common path + $traverser = str_repeat('../', $depth); + + // Construct $endPath from traversing to the common path, then to the remaining $endPath + $relativePath = $traverser.substr($endPath, $offset); + + return $relativePath; + } } From e7481a3f75ba8f8c6d07d950f62186b545101dc6 Mon Sep 17 00:00:00 2001 From: Brian King Date: Tue, 21 Jun 2011 10:50:14 +0200 Subject: [PATCH 004/196] Decouple mime-type to extension logic from File class --- .../Component/HttpFoundation/File/File.php | 421 +--------------- .../File/MimeType/ExtensionGuesser.php | 449 ++++++++++++++++++ 2 files changed, 451 insertions(+), 419 deletions(-) create mode 100644 src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesser.php diff --git a/src/Symfony/Component/HttpFoundation/File/File.php b/src/Symfony/Component/HttpFoundation/File/File.php index 32c79e520cb66..b0c2a254ccc7a 100644 --- a/src/Symfony/Component/HttpFoundation/File/File.php +++ b/src/Symfony/Component/HttpFoundation/File/File.php @@ -14,6 +14,7 @@ use Symfony\Component\HttpFoundation\File\Exception\FileException; use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; +use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser; /** * A file in the file system. @@ -22,424 +23,6 @@ */ class File extends \SplFileInfo { - /** - * A map of mime types and their default extensions. - * - * @var array - */ - static protected $defaultExtensions = array( - 'application/andrew-inset' => 'ez', - 'application/appledouble' => 'base64', - 'application/applefile' => 'base64', - 'application/commonground' => 'dp', - 'application/cprplayer' => 'pqi', - 'application/dsptype' => 'tsp', - 'application/excel' => 'xls', - 'application/font-tdpfr' => 'pfr', - 'application/futuresplash' => 'spl', - 'application/hstu' => 'stk', - 'application/hyperstudio' => 'stk', - 'application/javascript' => 'js', - 'application/mac-binhex40' => 'hqx', - 'application/mac-compactpro' => 'cpt', - 'application/mbed' => 'mbd', - 'application/mirage' => 'mfp', - 'application/msword' => 'doc', - 'application/ocsp-request' => 'orq', - 'application/ocsp-response' => 'ors', - 'application/octet-stream' => 'bin', - 'application/oda' => 'oda', - 'application/ogg' => 'ogg', - 'application/pdf' => 'pdf', - 'application/x-pdf' => 'pdf', - 'application/pgp-encrypted' => '7bit', - 'application/pgp-keys' => '7bit', - 'application/pgp-signature' => 'sig', - 'application/pkcs10' => 'p10', - 'application/pkcs7-mime' => 'p7m', - 'application/pkcs7-signature' => 'p7s', - 'application/pkix-cert' => 'cer', - 'application/pkix-crl' => 'crl', - 'application/pkix-pkipath' => 'pkipath', - 'application/pkixcmp' => 'pki', - 'application/postscript' => 'ps', - 'application/presentations' => 'shw', - 'application/prs.cww' => 'cw', - 'application/prs.nprend' => 'rnd', - 'application/quest' => 'qrt', - 'application/rtf' => 'rtf', - 'application/sgml-open-catalog' => 'soc', - 'application/sieve' => 'siv', - 'application/smil' => 'smi', - 'application/toolbook' => 'tbk', - 'application/vnd.3gpp.pic-bw-large' => 'plb', - 'application/vnd.3gpp.pic-bw-small' => 'psb', - 'application/vnd.3gpp.pic-bw-var' => 'pvb', - 'application/vnd.3gpp.sms' => 'sms', - 'application/vnd.acucorp' => 'atc', - 'application/vnd.adobe.xfdf' => 'xfdf', - 'application/vnd.amiga.amu' => 'ami', - 'application/vnd.blueice.multipass' => 'mpm', - 'application/vnd.cinderella' => 'cdy', - 'application/vnd.cosmocaller' => 'cmc', - 'application/vnd.criticaltools.wbs+xml' => 'wbs', - 'application/vnd.curl' => 'curl', - 'application/vnd.data-vision.rdz' => 'rdz', - 'application/vnd.dreamfactory' => 'dfac', - 'application/vnd.fsc.weblaunch' => 'fsc', - 'application/vnd.genomatix.tuxedo' => 'txd', - 'application/vnd.hbci' => 'hbci', - 'application/vnd.hhe.lesson-player' => 'les', - 'application/vnd.hp-hpgl' => 'plt', - 'application/vnd.ibm.electronic-media' => 'emm', - 'application/vnd.ibm.rights-management' => 'irm', - 'application/vnd.ibm.secure-container' => 'sc', - 'application/vnd.ipunplugged.rcprofile' => 'rcprofile', - 'application/vnd.irepository.package+xml' => 'irp', - 'application/vnd.jisp' => 'jisp', - 'application/vnd.kde.karbon' => 'karbon', - 'application/vnd.kde.kchart' => 'chrt', - 'application/vnd.kde.kformula' => 'kfo', - 'application/vnd.kde.kivio' => 'flw', - 'application/vnd.kde.kontour' => 'kon', - 'application/vnd.kde.kpresenter' => 'kpr', - 'application/vnd.kde.kspread' => 'ksp', - 'application/vnd.kde.kword' => 'kwd', - 'application/vnd.kenameapp' => 'htke', - 'application/vnd.kidspiration' => 'kia', - 'application/vnd.kinar' => 'kne', - 'application/vnd.llamagraphics.life-balance.desktop' => 'lbd', - 'application/vnd.llamagraphics.life-balance.exchange+xml' => 'lbe', - 'application/vnd.lotus-1-2-3' => 'wks', - 'application/vnd.mcd' => 'mcd', - 'application/vnd.mfmp' => 'mfm', - 'application/vnd.micrografx.flo' => 'flo', - 'application/vnd.micrografx.igx' => 'igx', - 'application/vnd.mif' => 'mif', - 'application/vnd.mophun.application' => 'mpn', - 'application/vnd.mophun.certificate' => 'mpc', - 'application/vnd.mozilla.xul+xml' => 'xul', - 'application/vnd.ms-artgalry' => 'cil', - 'application/vnd.ms-asf' => 'asf', - 'application/vnd.ms-excel' => 'xls', - 'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm', - 'application/vnd.ms-lrm' => 'lrm', - 'application/vnd.ms-powerpoint' => 'ppt', - 'application/vnd.ms-project' => 'mpp', - 'application/vnd.ms-tnef' => 'base64', - 'application/vnd.ms-works' => 'base64', - 'application/vnd.ms-wpl' => 'wpl', - 'application/vnd.mseq' => 'mseq', - 'application/vnd.nervana' => 'ent', - 'application/vnd.nokia.radio-preset' => 'rpst', - 'application/vnd.nokia.radio-presets' => 'rpss', - 'application/vnd.oasis.opendocument.text' => 'odt', - 'application/vnd.oasis.opendocument.text-template' => 'ott', - 'application/vnd.oasis.opendocument.text-web' => 'oth', - 'application/vnd.oasis.opendocument.text-master' => 'odm', - 'application/vnd.oasis.opendocument.graphics' => 'odg', - 'application/vnd.oasis.opendocument.graphics-template' => 'otg', - 'application/vnd.oasis.opendocument.presentation' => 'odp', - 'application/vnd.oasis.opendocument.presentation-template' => 'otp', - 'application/vnd.oasis.opendocument.spreadsheet' => 'ods', - 'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots', - 'application/vnd.oasis.opendocument.chart' => 'odc', - 'application/vnd.oasis.opendocument.formula' => 'odf', - 'application/vnd.oasis.opendocument.database' => 'odb', - 'application/vnd.oasis.opendocument.image' => 'odi', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', - 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx', - 'application/vnd.palm' => 'prc', - 'application/vnd.picsel' => 'efif', - 'application/vnd.pvi.ptid1' => 'pti', - 'application/vnd.quark.quarkxpress' => 'qxd', - 'application/vnd.sealed.doc' => 'sdoc', - 'application/vnd.sealed.eml' => 'seml', - 'application/vnd.sealed.mht' => 'smht', - 'application/vnd.sealed.ppt' => 'sppt', - 'application/vnd.sealed.xls' => 'sxls', - 'application/vnd.sealedmedia.softseal.html' => 'stml', - 'application/vnd.sealedmedia.softseal.pdf' => 'spdf', - 'application/vnd.seemail' => 'see', - 'application/vnd.smaf' => 'mmf', - 'application/vnd.sun.xml.calc' => 'sxc', - 'application/vnd.sun.xml.calc.template' => 'stc', - 'application/vnd.sun.xml.draw' => 'sxd', - 'application/vnd.sun.xml.draw.template' => 'std', - 'application/vnd.sun.xml.impress' => 'sxi', - 'application/vnd.sun.xml.impress.template' => 'sti', - 'application/vnd.sun.xml.math' => 'sxm', - 'application/vnd.sun.xml.writer' => 'sxw', - 'application/vnd.sun.xml.writer.global' => 'sxg', - 'application/vnd.sun.xml.writer.template' => 'stw', - 'application/vnd.sus-calendar' => 'sus', - 'application/vnd.vidsoft.vidconference' => 'vsc', - 'application/vnd.visio' => 'vsd', - 'application/vnd.visionary' => 'vis', - 'application/vnd.wap.sic' => 'sic', - 'application/vnd.wap.slc' => 'slc', - 'application/vnd.wap.wbxml' => 'wbxml', - 'application/vnd.wap.wmlc' => 'wmlc', - 'application/vnd.wap.wmlscriptc' => 'wmlsc', - 'application/vnd.webturbo' => 'wtb', - 'application/vnd.wordperfect' => 'wpd', - 'application/vnd.wqd' => 'wqd', - 'application/vnd.wv.csp+wbxml' => 'wv', - 'application/vnd.wv.csp+xml' => '8bit', - 'application/vnd.wv.ssp+xml' => '8bit', - 'application/vnd.yamaha.hv-dic' => 'hvd', - 'application/vnd.yamaha.hv-script' => 'hvs', - 'application/vnd.yamaha.hv-voice' => 'hvp', - 'application/vnd.yamaha.smaf-audio' => 'saf', - 'application/vnd.yamaha.smaf-phrase' => 'spf', - 'application/vocaltec-media-desc' => 'vmd', - 'application/vocaltec-media-file' => 'vmf', - 'application/vocaltec-talker' => 'vtk', - 'application/watcherinfo+xml' => 'wif', - 'application/wordperfect5.1' => 'wp5', - 'application/x-123' => 'wk', - 'application/x-7th_level_event' => '7ls', - 'application/x-authorware-bin' => 'aab', - 'application/x-authorware-map' => 'aam', - 'application/x-authorware-seg' => 'aas', - 'application/x-bcpio' => 'bcpio', - 'application/x-bleeper' => 'bleep', - 'application/x-bzip2' => 'bz2', - 'application/x-cdlink' => 'vcd', - 'application/x-chat' => 'chat', - 'application/x-chess-pgn' => 'pgn', - 'application/x-compress' => 'z', - 'application/x-cpio' => 'cpio', - 'application/x-cprplayer' => 'pqf', - 'application/x-csh' => 'csh', - 'application/x-cu-seeme' => 'csm', - 'application/x-cult3d-object' => 'co', - 'application/x-debian-package' => 'deb', - 'application/x-director' => 'dcr', - 'application/x-dvi' => 'dvi', - 'application/x-envoy' => 'evy', - 'application/x-futuresplash' => 'spl', - 'application/x-gtar' => 'gtar', - 'application/x-gzip' => 'gz', - 'application/x-hdf' => 'hdf', - 'application/x-hep' => 'hep', - 'application/x-html+ruby' => 'rhtml', - 'application/x-httpd-miva' => 'mv', - 'application/x-httpd-php' => 'phtml', - 'application/x-ica' => 'ica', - 'application/x-imagemap' => 'imagemap', - 'application/x-ipix' => 'ipx', - 'application/x-ipscript' => 'ips', - 'application/x-java-archive' => 'jar', - 'application/x-java-jnlp-file' => 'jnlp', - 'application/x-java-serialized-object' => 'ser', - 'application/x-java-vm' => 'class', - 'application/x-javascript' => 'js', - 'application/x-koan' => 'skp', - 'application/x-latex' => 'latex', - 'application/x-mac-compactpro' => 'cpt', - 'application/x-maker' => 'frm', - 'application/x-mathcad' => 'mcd', - 'application/x-midi' => 'mid', - 'application/x-mif' => 'mif', - 'application/x-msaccess' => 'mda', - 'application/x-msdos-program' => 'com', - 'application/x-msdownload' => 'base64', - 'application/x-msexcel' => 'xls', - 'application/x-msword' => 'doc', - 'application/x-netcdf' => 'nc', - 'application/x-ns-proxy-autoconfig' => 'pac', - 'application/x-pagemaker' => 'pm5', - 'application/x-perl' => 'pl', - 'application/x-pn-realmedia' => 'rp', - 'application/x-python' => 'py', - 'application/x-quicktimeplayer' => 'qtl', - 'application/x-rar-compressed' => 'rar', - 'application/x-ruby' => 'rb', - 'application/x-sh' => 'sh', - 'application/x-shar' => 'shar', - 'application/x-shockwave-flash' => 'swf', - 'application/x-sprite' => 'spr', - 'application/x-spss' => 'sav', - 'application/x-spt' => 'spt', - 'application/x-stuffit' => 'sit', - 'application/x-sv4cpio' => 'sv4cpio', - 'application/x-sv4crc' => 'sv4crc', - 'application/x-tar' => 'tar', - 'application/x-tcl' => 'tcl', - 'application/x-tex' => 'tex', - 'application/x-texinfo' => 'texinfo', - 'application/x-troff' => 't', - 'application/x-troff-man' => 'man', - 'application/x-troff-me' => 'me', - 'application/x-troff-ms' => 'ms', - 'application/x-twinvq' => 'vqf', - 'application/x-twinvq-plugin' => 'vqe', - 'application/x-ustar' => 'ustar', - 'application/x-vmsbackup' => 'bck', - 'application/x-wais-source' => 'src', - 'application/x-wingz' => 'wz', - 'application/x-word' => 'base64', - 'application/x-wordperfect6.1' => 'wp6', - 'application/x-x509-ca-cert' => 'crt', - 'application/x-zip-compressed' => 'zip', - 'application/xhtml+xml' => 'xhtml', - 'application/zip' => 'zip', - 'audio/3gpp' => '3gpp', - 'audio/amr' => 'amr', - 'audio/amr-wb' => 'awb', - 'audio/basic' => 'au', - 'audio/evrc' => 'evc', - 'audio/l16' => 'l16', - 'audio/midi' => 'mid', - 'audio/mpeg' => 'mp3', - 'audio/prs.sid' => 'sid', - 'audio/qcelp' => 'qcp', - 'audio/smv' => 'smv', - 'audio/vnd.audiokoz' => 'koz', - 'audio/vnd.digital-winds' => 'eol', - 'audio/vnd.everad.plj' => 'plj', - 'audio/vnd.lucent.voice' => 'lvp', - 'audio/vnd.nokia.mobile-xmf' => 'mxmf', - 'audio/vnd.nortel.vbk' => 'vbk', - 'audio/vnd.nuera.ecelp4800' => 'ecelp4800', - 'audio/vnd.nuera.ecelp7470' => 'ecelp7470', - 'audio/vnd.nuera.ecelp9600' => 'ecelp9600', - 'audio/vnd.sealedmedia.softseal.mpeg' => 'smp3', - 'audio/voxware' => 'vox', - 'audio/x-aiff' => 'aif', - 'audio/x-mid' => 'mid', - 'audio/x-midi' => 'mid', - 'audio/x-mpeg' => 'mp2', - 'audio/x-mpegurl' => 'mpu', - 'audio/x-pn-realaudio' => 'rm', - 'audio/x-pn-realaudio-plugin' => 'rpm', - 'audio/x-realaudio' => 'ra', - 'audio/x-wav' => 'wav', - 'chemical/x-csml' => 'csm', - 'chemical/x-embl-dl-nucleotide' => 'emb', - 'chemical/x-gaussian-cube' => 'cube', - 'chemical/x-gaussian-input' => 'gau', - 'chemical/x-jcamp-dx' => 'jdx', - 'chemical/x-mdl-molfile' => 'mol', - 'chemical/x-mdl-rxnfile' => 'rxn', - 'chemical/x-mdl-tgf' => 'tgf', - 'chemical/x-mopac-input' => 'mop', - 'chemical/x-pdb' => 'pdb', - 'chemical/x-rasmol' => 'scr', - 'chemical/x-xyz' => 'xyz', - 'drawing/dwf' => 'dwf', - 'drawing/x-dwf' => 'dwf', - 'i-world/i-vrml' => 'ivr', - 'image/bmp' => 'bmp', - 'image/cewavelet' => 'wif', - 'image/cis-cod' => 'cod', - 'image/fif' => 'fif', - 'image/gif' => 'gif', - 'image/ief' => 'ief', - 'image/jp2' => 'jp2', - 'image/jpeg' => 'jpg', - 'image/jpm' => 'jpm', - 'image/jpx' => 'jpf', - 'image/pict' => 'pic', - 'image/pjpeg' => 'jpg', - 'image/png' => 'png', - 'image/targa' => 'tga', - 'image/tiff' => 'tif', - 'image/vn-svf' => 'svf', - 'image/vnd.dgn' => 'dgn', - 'image/vnd.djvu' => 'djvu', - 'image/vnd.dwg' => 'dwg', - 'image/vnd.glocalgraphics.pgb' => 'pgb', - 'image/vnd.microsoft.icon' => 'ico', - 'image/vnd.ms-modi' => 'mdi', - 'image/vnd.sealed.png' => 'spng', - 'image/vnd.sealedmedia.softseal.gif' => 'sgif', - 'image/vnd.sealedmedia.softseal.jpg' => 'sjpg', - 'image/vnd.wap.wbmp' => 'wbmp', - 'image/x-bmp' => 'bmp', - 'image/x-cmu-raster' => 'ras', - 'image/x-freehand' => 'fh4', - 'image/x-png' => 'png', - 'image/x-portable-anymap' => 'pnm', - 'image/x-portable-bitmap' => 'pbm', - 'image/x-portable-graymap' => 'pgm', - 'image/x-portable-pixmap' => 'ppm', - 'image/x-rgb' => 'rgb', - 'image/x-xbitmap' => 'xbm', - 'image/x-xpixmap' => 'xpm', - 'image/x-xwindowdump' => 'xwd', - 'message/external-body' => '8bit', - 'message/news' => '8bit', - 'message/partial' => '8bit', - 'message/rfc822' => '8bit', - 'model/iges' => 'igs', - 'model/mesh' => 'msh', - 'model/vnd.parasolid.transmit.binary' => 'x_b', - 'model/vnd.parasolid.transmit.text' => 'x_t', - 'model/vrml' => 'wrl', - 'multipart/alternative' => '8bit', - 'multipart/appledouble' => '8bit', - 'multipart/digest' => '8bit', - 'multipart/mixed' => '8bit', - 'multipart/parallel' => '8bit', - 'text/comma-separated-values' => 'csv', - 'text/css' => 'css', - 'text/html' => 'html', - 'text/plain' => 'txt', - 'text/prs.fallenstein.rst' => 'rst', - 'text/richtext' => 'rtx', - 'text/rtf' => 'rtf', - 'text/sgml' => 'sgml', - 'text/tab-separated-values' => 'tsv', - 'text/vnd.net2phone.commcenter.command' => 'ccc', - 'text/vnd.sun.j2me.app-descriptor' => 'jad', - 'text/vnd.wap.si' => 'si', - 'text/vnd.wap.sl' => 'sl', - 'text/vnd.wap.wml' => 'wml', - 'text/vnd.wap.wmlscript' => 'wmls', - 'text/x-hdml' => 'hdml', - 'text/x-setext' => 'etx', - 'text/x-sgml' => 'sgml', - 'text/x-speech' => 'talk', - 'text/x-vcalendar' => 'vcs', - 'text/x-vcard' => 'vcf', - 'text/xml' => 'xml', - 'ulead/vrml' => 'uvr', - 'video/3gpp' => '3gp', - 'video/dl' => 'dl', - 'video/gl' => 'gl', - 'video/mj2' => 'mj2', - 'video/mpeg' => 'mpeg', - 'video/quicktime' => 'mov', - 'video/vdo' => 'vdo', - 'video/vivo' => 'viv', - 'video/vnd.fvt' => 'fvt', - 'video/vnd.mpegurl' => 'mxu', - 'video/vnd.nokia.interleaved-multimedia' => 'nim', - 'video/vnd.objectvideo' => 'mp4', - 'video/vnd.sealed.mpeg1' => 's11', - 'video/vnd.sealed.mpeg4' => 'smpg', - 'video/vnd.sealed.swf' => 'sswf', - 'video/vnd.sealedmedia.softseal.mov' => 'smov', - 'video/vnd.vivo' => 'vivo', - 'video/x-fli' => 'fli', - 'video/x-ms-asf' => 'asf', - 'video/x-ms-wmv' => 'wmv', - 'video/x-msvideo' => 'avi', - 'video/x-sgi-movie' => 'movie', - 'x-chemical/x-pdb' => 'pdb', - 'x-chemical/x-xyz' => 'xyz', - 'x-conference/x-cooltalk' => 'ice', - 'x-drawing/dwf' => 'dwf', - 'x-world/x-d96' => 'd', - 'x-world/x-svr' => 'svr', - 'x-world/x-vream' => 'vrw', - 'x-world/x-vrml' => 'wrl', - ); - /** * Constructs a new file from the given path. * @@ -467,7 +50,7 @@ public function guessExtension() { $type = $this->getMimeType(); - return isset(static::$defaultExtensions[$type]) ? static::$defaultExtensions[$type] : null; + return ExtensionGuesser::guessExtension($type); } /** diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesser.php new file mode 100644 index 0000000000000..4313570d0743b --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesser.php @@ -0,0 +1,449 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation\File\Mimetype; + +/** + * Provides a best-guess mapping of mime-type to file extension. + */ +class ExtensionGuesser +{ + /** + * A map of mime types and their default extensions. + * + * @var array + */ + static protected $defaultExtensions = array( + 'application/andrew-inset' => 'ez', + 'application/appledouble' => 'base64', + 'application/applefile' => 'base64', + 'application/commonground' => 'dp', + 'application/cprplayer' => 'pqi', + 'application/dsptype' => 'tsp', + 'application/excel' => 'xls', + 'application/font-tdpfr' => 'pfr', + 'application/futuresplash' => 'spl', + 'application/hstu' => 'stk', + 'application/hyperstudio' => 'stk', + 'application/javascript' => 'js', + 'application/mac-binhex40' => 'hqx', + 'application/mac-compactpro' => 'cpt', + 'application/mbed' => 'mbd', + 'application/mirage' => 'mfp', + 'application/msword' => 'doc', + 'application/ocsp-request' => 'orq', + 'application/ocsp-response' => 'ors', + 'application/octet-stream' => 'bin', + 'application/oda' => 'oda', + 'application/ogg' => 'ogg', + 'application/pdf' => 'pdf', + 'application/x-pdf' => 'pdf', + 'application/pgp-encrypted' => '7bit', + 'application/pgp-keys' => '7bit', + 'application/pgp-signature' => 'sig', + 'application/pkcs10' => 'p10', + 'application/pkcs7-mime' => 'p7m', + 'application/pkcs7-signature' => 'p7s', + 'application/pkix-cert' => 'cer', + 'application/pkix-crl' => 'crl', + 'application/pkix-pkipath' => 'pkipath', + 'application/pkixcmp' => 'pki', + 'application/postscript' => 'ps', + 'application/presentations' => 'shw', + 'application/prs.cww' => 'cw', + 'application/prs.nprend' => 'rnd', + 'application/quest' => 'qrt', + 'application/rtf' => 'rtf', + 'application/sgml-open-catalog' => 'soc', + 'application/sieve' => 'siv', + 'application/smil' => 'smi', + 'application/toolbook' => 'tbk', + 'application/vnd.3gpp.pic-bw-large' => 'plb', + 'application/vnd.3gpp.pic-bw-small' => 'psb', + 'application/vnd.3gpp.pic-bw-var' => 'pvb', + 'application/vnd.3gpp.sms' => 'sms', + 'application/vnd.acucorp' => 'atc', + 'application/vnd.adobe.xfdf' => 'xfdf', + 'application/vnd.amiga.amu' => 'ami', + 'application/vnd.blueice.multipass' => 'mpm', + 'application/vnd.cinderella' => 'cdy', + 'application/vnd.cosmocaller' => 'cmc', + 'application/vnd.criticaltools.wbs+xml' => 'wbs', + 'application/vnd.curl' => 'curl', + 'application/vnd.data-vision.rdz' => 'rdz', + 'application/vnd.dreamfactory' => 'dfac', + 'application/vnd.fsc.weblaunch' => 'fsc', + 'application/vnd.genomatix.tuxedo' => 'txd', + 'application/vnd.hbci' => 'hbci', + 'application/vnd.hhe.lesson-player' => 'les', + 'application/vnd.hp-hpgl' => 'plt', + 'application/vnd.ibm.electronic-media' => 'emm', + 'application/vnd.ibm.rights-management' => 'irm', + 'application/vnd.ibm.secure-container' => 'sc', + 'application/vnd.ipunplugged.rcprofile' => 'rcprofile', + 'application/vnd.irepository.package+xml' => 'irp', + 'application/vnd.jisp' => 'jisp', + 'application/vnd.kde.karbon' => 'karbon', + 'application/vnd.kde.kchart' => 'chrt', + 'application/vnd.kde.kformula' => 'kfo', + 'application/vnd.kde.kivio' => 'flw', + 'application/vnd.kde.kontour' => 'kon', + 'application/vnd.kde.kpresenter' => 'kpr', + 'application/vnd.kde.kspread' => 'ksp', + 'application/vnd.kde.kword' => 'kwd', + 'application/vnd.kenameapp' => 'htke', + 'application/vnd.kidspiration' => 'kia', + 'application/vnd.kinar' => 'kne', + 'application/vnd.llamagraphics.life-balance.desktop' => 'lbd', + 'application/vnd.llamagraphics.life-balance.exchange+xml' => 'lbe', + 'application/vnd.lotus-1-2-3' => 'wks', + 'application/vnd.mcd' => 'mcd', + 'application/vnd.mfmp' => 'mfm', + 'application/vnd.micrografx.flo' => 'flo', + 'application/vnd.micrografx.igx' => 'igx', + 'application/vnd.mif' => 'mif', + 'application/vnd.mophun.application' => 'mpn', + 'application/vnd.mophun.certificate' => 'mpc', + 'application/vnd.mozilla.xul+xml' => 'xul', + 'application/vnd.ms-artgalry' => 'cil', + 'application/vnd.ms-asf' => 'asf', + 'application/vnd.ms-excel' => 'xls', + 'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm', + 'application/vnd.ms-lrm' => 'lrm', + 'application/vnd.ms-powerpoint' => 'ppt', + 'application/vnd.ms-project' => 'mpp', + 'application/vnd.ms-tnef' => 'base64', + 'application/vnd.ms-works' => 'base64', + 'application/vnd.ms-wpl' => 'wpl', + 'application/vnd.mseq' => 'mseq', + 'application/vnd.nervana' => 'ent', + 'application/vnd.nokia.radio-preset' => 'rpst', + 'application/vnd.nokia.radio-presets' => 'rpss', + 'application/vnd.oasis.opendocument.text' => 'odt', + 'application/vnd.oasis.opendocument.text-template' => 'ott', + 'application/vnd.oasis.opendocument.text-web' => 'oth', + 'application/vnd.oasis.opendocument.text-master' => 'odm', + 'application/vnd.oasis.opendocument.graphics' => 'odg', + 'application/vnd.oasis.opendocument.graphics-template' => 'otg', + 'application/vnd.oasis.opendocument.presentation' => 'odp', + 'application/vnd.oasis.opendocument.presentation-template' => 'otp', + 'application/vnd.oasis.opendocument.spreadsheet' => 'ods', + 'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots', + 'application/vnd.oasis.opendocument.chart' => 'odc', + 'application/vnd.oasis.opendocument.formula' => 'odf', + 'application/vnd.oasis.opendocument.database' => 'odb', + 'application/vnd.oasis.opendocument.image' => 'odi', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', + 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx', + 'application/vnd.palm' => 'prc', + 'application/vnd.picsel' => 'efif', + 'application/vnd.pvi.ptid1' => 'pti', + 'application/vnd.quark.quarkxpress' => 'qxd', + 'application/vnd.sealed.doc' => 'sdoc', + 'application/vnd.sealed.eml' => 'seml', + 'application/vnd.sealed.mht' => 'smht', + 'application/vnd.sealed.ppt' => 'sppt', + 'application/vnd.sealed.xls' => 'sxls', + 'application/vnd.sealedmedia.softseal.html' => 'stml', + 'application/vnd.sealedmedia.softseal.pdf' => 'spdf', + 'application/vnd.seemail' => 'see', + 'application/vnd.smaf' => 'mmf', + 'application/vnd.sun.xml.calc' => 'sxc', + 'application/vnd.sun.xml.calc.template' => 'stc', + 'application/vnd.sun.xml.draw' => 'sxd', + 'application/vnd.sun.xml.draw.template' => 'std', + 'application/vnd.sun.xml.impress' => 'sxi', + 'application/vnd.sun.xml.impress.template' => 'sti', + 'application/vnd.sun.xml.math' => 'sxm', + 'application/vnd.sun.xml.writer' => 'sxw', + 'application/vnd.sun.xml.writer.global' => 'sxg', + 'application/vnd.sun.xml.writer.template' => 'stw', + 'application/vnd.sus-calendar' => 'sus', + 'application/vnd.vidsoft.vidconference' => 'vsc', + 'application/vnd.visio' => 'vsd', + 'application/vnd.visionary' => 'vis', + 'application/vnd.wap.sic' => 'sic', + 'application/vnd.wap.slc' => 'slc', + 'application/vnd.wap.wbxml' => 'wbxml', + 'application/vnd.wap.wmlc' => 'wmlc', + 'application/vnd.wap.wmlscriptc' => 'wmlsc', + 'application/vnd.webturbo' => 'wtb', + 'application/vnd.wordperfect' => 'wpd', + 'application/vnd.wqd' => 'wqd', + 'application/vnd.wv.csp+wbxml' => 'wv', + 'application/vnd.wv.csp+xml' => '8bit', + 'application/vnd.wv.ssp+xml' => '8bit', + 'application/vnd.yamaha.hv-dic' => 'hvd', + 'application/vnd.yamaha.hv-script' => 'hvs', + 'application/vnd.yamaha.hv-voice' => 'hvp', + 'application/vnd.yamaha.smaf-audio' => 'saf', + 'application/vnd.yamaha.smaf-phrase' => 'spf', + 'application/vocaltec-media-desc' => 'vmd', + 'application/vocaltec-media-file' => 'vmf', + 'application/vocaltec-talker' => 'vtk', + 'application/watcherinfo+xml' => 'wif', + 'application/wordperfect5.1' => 'wp5', + 'application/x-123' => 'wk', + 'application/x-7th_level_event' => '7ls', + 'application/x-authorware-bin' => 'aab', + 'application/x-authorware-map' => 'aam', + 'application/x-authorware-seg' => 'aas', + 'application/x-bcpio' => 'bcpio', + 'application/x-bleeper' => 'bleep', + 'application/x-bzip2' => 'bz2', + 'application/x-cdlink' => 'vcd', + 'application/x-chat' => 'chat', + 'application/x-chess-pgn' => 'pgn', + 'application/x-compress' => 'z', + 'application/x-cpio' => 'cpio', + 'application/x-cprplayer' => 'pqf', + 'application/x-csh' => 'csh', + 'application/x-cu-seeme' => 'csm', + 'application/x-cult3d-object' => 'co', + 'application/x-debian-package' => 'deb', + 'application/x-director' => 'dcr', + 'application/x-dvi' => 'dvi', + 'application/x-envoy' => 'evy', + 'application/x-futuresplash' => 'spl', + 'application/x-gtar' => 'gtar', + 'application/x-gzip' => 'gz', + 'application/x-hdf' => 'hdf', + 'application/x-hep' => 'hep', + 'application/x-html+ruby' => 'rhtml', + 'application/x-httpd-miva' => 'mv', + 'application/x-httpd-php' => 'phtml', + 'application/x-ica' => 'ica', + 'application/x-imagemap' => 'imagemap', + 'application/x-ipix' => 'ipx', + 'application/x-ipscript' => 'ips', + 'application/x-java-archive' => 'jar', + 'application/x-java-jnlp-file' => 'jnlp', + 'application/x-java-serialized-object' => 'ser', + 'application/x-java-vm' => 'class', + 'application/x-javascript' => 'js', + 'application/x-koan' => 'skp', + 'application/x-latex' => 'latex', + 'application/x-mac-compactpro' => 'cpt', + 'application/x-maker' => 'frm', + 'application/x-mathcad' => 'mcd', + 'application/x-midi' => 'mid', + 'application/x-mif' => 'mif', + 'application/x-msaccess' => 'mda', + 'application/x-msdos-program' => 'com', + 'application/x-msdownload' => 'base64', + 'application/x-msexcel' => 'xls', + 'application/x-msword' => 'doc', + 'application/x-netcdf' => 'nc', + 'application/x-ns-proxy-autoconfig' => 'pac', + 'application/x-pagemaker' => 'pm5', + 'application/x-perl' => 'pl', + 'application/x-pn-realmedia' => 'rp', + 'application/x-python' => 'py', + 'application/x-quicktimeplayer' => 'qtl', + 'application/x-rar-compressed' => 'rar', + 'application/x-ruby' => 'rb', + 'application/x-sh' => 'sh', + 'application/x-shar' => 'shar', + 'application/x-shockwave-flash' => 'swf', + 'application/x-sprite' => 'spr', + 'application/x-spss' => 'sav', + 'application/x-spt' => 'spt', + 'application/x-stuffit' => 'sit', + 'application/x-sv4cpio' => 'sv4cpio', + 'application/x-sv4crc' => 'sv4crc', + 'application/x-tar' => 'tar', + 'application/x-tcl' => 'tcl', + 'application/x-tex' => 'tex', + 'application/x-texinfo' => 'texinfo', + 'application/x-troff' => 't', + 'application/x-troff-man' => 'man', + 'application/x-troff-me' => 'me', + 'application/x-troff-ms' => 'ms', + 'application/x-twinvq' => 'vqf', + 'application/x-twinvq-plugin' => 'vqe', + 'application/x-ustar' => 'ustar', + 'application/x-vmsbackup' => 'bck', + 'application/x-wais-source' => 'src', + 'application/x-wingz' => 'wz', + 'application/x-word' => 'base64', + 'application/x-wordperfect6.1' => 'wp6', + 'application/x-x509-ca-cert' => 'crt', + 'application/x-zip-compressed' => 'zip', + 'application/xhtml+xml' => 'xhtml', + 'application/zip' => 'zip', + 'audio/3gpp' => '3gpp', + 'audio/amr' => 'amr', + 'audio/amr-wb' => 'awb', + 'audio/basic' => 'au', + 'audio/evrc' => 'evc', + 'audio/l16' => 'l16', + 'audio/midi' => 'mid', + 'audio/mpeg' => 'mp3', + 'audio/prs.sid' => 'sid', + 'audio/qcelp' => 'qcp', + 'audio/smv' => 'smv', + 'audio/vnd.audiokoz' => 'koz', + 'audio/vnd.digital-winds' => 'eol', + 'audio/vnd.everad.plj' => 'plj', + 'audio/vnd.lucent.voice' => 'lvp', + 'audio/vnd.nokia.mobile-xmf' => 'mxmf', + 'audio/vnd.nortel.vbk' => 'vbk', + 'audio/vnd.nuera.ecelp4800' => 'ecelp4800', + 'audio/vnd.nuera.ecelp7470' => 'ecelp7470', + 'audio/vnd.nuera.ecelp9600' => 'ecelp9600', + 'audio/vnd.sealedmedia.softseal.mpeg' => 'smp3', + 'audio/voxware' => 'vox', + 'audio/x-aiff' => 'aif', + 'audio/x-mid' => 'mid', + 'audio/x-midi' => 'mid', + 'audio/x-mpeg' => 'mp2', + 'audio/x-mpegurl' => 'mpu', + 'audio/x-pn-realaudio' => 'rm', + 'audio/x-pn-realaudio-plugin' => 'rpm', + 'audio/x-realaudio' => 'ra', + 'audio/x-wav' => 'wav', + 'chemical/x-csml' => 'csm', + 'chemical/x-embl-dl-nucleotide' => 'emb', + 'chemical/x-gaussian-cube' => 'cube', + 'chemical/x-gaussian-input' => 'gau', + 'chemical/x-jcamp-dx' => 'jdx', + 'chemical/x-mdl-molfile' => 'mol', + 'chemical/x-mdl-rxnfile' => 'rxn', + 'chemical/x-mdl-tgf' => 'tgf', + 'chemical/x-mopac-input' => 'mop', + 'chemical/x-pdb' => 'pdb', + 'chemical/x-rasmol' => 'scr', + 'chemical/x-xyz' => 'xyz', + 'drawing/dwf' => 'dwf', + 'drawing/x-dwf' => 'dwf', + 'i-world/i-vrml' => 'ivr', + 'image/bmp' => 'bmp', + 'image/cewavelet' => 'wif', + 'image/cis-cod' => 'cod', + 'image/fif' => 'fif', + 'image/gif' => 'gif', + 'image/ief' => 'ief', + 'image/jp2' => 'jp2', + 'image/jpeg' => 'jpg', + 'image/jpm' => 'jpm', + 'image/jpx' => 'jpf', + 'image/pict' => 'pic', + 'image/pjpeg' => 'jpg', + 'image/png' => 'png', + 'image/targa' => 'tga', + 'image/tiff' => 'tif', + 'image/vn-svf' => 'svf', + 'image/vnd.dgn' => 'dgn', + 'image/vnd.djvu' => 'djvu', + 'image/vnd.dwg' => 'dwg', + 'image/vnd.glocalgraphics.pgb' => 'pgb', + 'image/vnd.microsoft.icon' => 'ico', + 'image/vnd.ms-modi' => 'mdi', + 'image/vnd.sealed.png' => 'spng', + 'image/vnd.sealedmedia.softseal.gif' => 'sgif', + 'image/vnd.sealedmedia.softseal.jpg' => 'sjpg', + 'image/vnd.wap.wbmp' => 'wbmp', + 'image/x-bmp' => 'bmp', + 'image/x-cmu-raster' => 'ras', + 'image/x-freehand' => 'fh4', + 'image/x-png' => 'png', + 'image/x-portable-anymap' => 'pnm', + 'image/x-portable-bitmap' => 'pbm', + 'image/x-portable-graymap' => 'pgm', + 'image/x-portable-pixmap' => 'ppm', + 'image/x-rgb' => 'rgb', + 'image/x-xbitmap' => 'xbm', + 'image/x-xpixmap' => 'xpm', + 'image/x-xwindowdump' => 'xwd', + 'message/external-body' => '8bit', + 'message/news' => '8bit', + 'message/partial' => '8bit', + 'message/rfc822' => '8bit', + 'model/iges' => 'igs', + 'model/mesh' => 'msh', + 'model/vnd.parasolid.transmit.binary' => 'x_b', + 'model/vnd.parasolid.transmit.text' => 'x_t', + 'model/vrml' => 'wrl', + 'multipart/alternative' => '8bit', + 'multipart/appledouble' => '8bit', + 'multipart/digest' => '8bit', + 'multipart/mixed' => '8bit', + 'multipart/parallel' => '8bit', + 'text/comma-separated-values' => 'csv', + 'text/css' => 'css', + 'text/html' => 'html', + 'text/plain' => 'txt', + 'text/prs.fallenstein.rst' => 'rst', + 'text/richtext' => 'rtx', + 'text/rtf' => 'rtf', + 'text/sgml' => 'sgml', + 'text/tab-separated-values' => 'tsv', + 'text/vnd.net2phone.commcenter.command' => 'ccc', + 'text/vnd.sun.j2me.app-descriptor' => 'jad', + 'text/vnd.wap.si' => 'si', + 'text/vnd.wap.sl' => 'sl', + 'text/vnd.wap.wml' => 'wml', + 'text/vnd.wap.wmlscript' => 'wmls', + 'text/x-hdml' => 'hdml', + 'text/x-setext' => 'etx', + 'text/x-sgml' => 'sgml', + 'text/x-speech' => 'talk', + 'text/x-vcalendar' => 'vcs', + 'text/x-vcard' => 'vcf', + 'text/xml' => 'xml', + 'ulead/vrml' => 'uvr', + 'video/3gpp' => '3gp', + 'video/dl' => 'dl', + 'video/gl' => 'gl', + 'video/mj2' => 'mj2', + 'video/mpeg' => 'mpeg', + 'video/quicktime' => 'mov', + 'video/vdo' => 'vdo', + 'video/vivo' => 'viv', + 'video/vnd.fvt' => 'fvt', + 'video/vnd.mpegurl' => 'mxu', + 'video/vnd.nokia.interleaved-multimedia' => 'nim', + 'video/vnd.objectvideo' => 'mp4', + 'video/vnd.sealed.mpeg1' => 's11', + 'video/vnd.sealed.mpeg4' => 'smpg', + 'video/vnd.sealed.swf' => 'sswf', + 'video/vnd.sealedmedia.softseal.mov' => 'smov', + 'video/vnd.vivo' => 'vivo', + 'video/x-fli' => 'fli', + 'video/x-ms-asf' => 'asf', + 'video/x-ms-wmv' => 'wmv', + 'video/x-msvideo' => 'avi', + 'video/x-sgi-movie' => 'movie', + 'x-chemical/x-pdb' => 'pdb', + 'x-chemical/x-xyz' => 'xyz', + 'x-conference/x-cooltalk' => 'ice', + 'x-drawing/dwf' => 'dwf', + 'x-world/x-d96' => 'd', + 'x-world/x-svr' => 'svr', + 'x-world/x-vream' => 'vrw', + 'x-world/x-vrml' => 'wrl', + ); + + /** + * Returns the extension based on the mime type. + * + * If the mime type is unknown, returns null. + * + * @return string|null The guessed extension or null if it cannot be guessed + */ + static function guessExtension($mimeType) + { + return isset(static::$defaultExtensions[$mimeType]) ? static::$defaultExtensions[$mimeType] : null; + } + +} From 1a86a4a215778549042e5706972ed5de2c8aee78 Mon Sep 17 00:00:00 2001 From: Brian King Date: Tue, 21 Jun 2011 13:31:24 +0200 Subject: [PATCH 005/196] Refactor mime-type to file extension guessing --- .../Component/HttpFoundation/File/File.php | 3 +- .../File/MimeType/ExtensionGuesser.php | 495 +++--------------- .../MimeType/ExtensionGuesserInterface.php | 27 + .../MimeType/MimeTypeExtensionGuesser.php | 449 ++++++++++++++++ 4 files changed, 551 insertions(+), 423 deletions(-) create mode 100644 src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesserInterface.php create mode 100644 src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeExtensionGuesser.php diff --git a/src/Symfony/Component/HttpFoundation/File/File.php b/src/Symfony/Component/HttpFoundation/File/File.php index b0c2a254ccc7a..a646564ad5429 100644 --- a/src/Symfony/Component/HttpFoundation/File/File.php +++ b/src/Symfony/Component/HttpFoundation/File/File.php @@ -49,8 +49,9 @@ public function __construct($path) public function guessExtension() { $type = $this->getMimeType(); + $guesser = ExtensionGuesser::getInstance(); - return ExtensionGuesser::guessExtension($type); + return $guesser->guess($type); } /** diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesser.php index 4313570d0743b..b73cd999107c6 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesser.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesser.php @@ -9,441 +9,92 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpFoundation\File\Mimetype; +namespace Symfony\Component\HttpFoundation\File\MimeType; /** - * Provides a best-guess mapping of mime-type to file extension. + * A singleton mime type to file extension guesser. + * + * A default guesser is provided. + * You can register custom guessers by calling the register() + * method on the singleton instance. + * + * + * $guesser = ExtensionGuesser::getInstance(); + * $guesser->register(new MyCustomExtensionGuesser()); + * + * + * The last registered guesser is preferred over previously registered ones. + * */ -class ExtensionGuesser +class ExtensionGuesser implements ExtensionGuesserInterface { /** - * A map of mime types and their default extensions. - * + * The singleton instance + * @var ExtensionGuesser + */ + static private $instance = null; + + /** + * All registered ExtensionGuesserInterface instances * @var array */ - static protected $defaultExtensions = array( - 'application/andrew-inset' => 'ez', - 'application/appledouble' => 'base64', - 'application/applefile' => 'base64', - 'application/commonground' => 'dp', - 'application/cprplayer' => 'pqi', - 'application/dsptype' => 'tsp', - 'application/excel' => 'xls', - 'application/font-tdpfr' => 'pfr', - 'application/futuresplash' => 'spl', - 'application/hstu' => 'stk', - 'application/hyperstudio' => 'stk', - 'application/javascript' => 'js', - 'application/mac-binhex40' => 'hqx', - 'application/mac-compactpro' => 'cpt', - 'application/mbed' => 'mbd', - 'application/mirage' => 'mfp', - 'application/msword' => 'doc', - 'application/ocsp-request' => 'orq', - 'application/ocsp-response' => 'ors', - 'application/octet-stream' => 'bin', - 'application/oda' => 'oda', - 'application/ogg' => 'ogg', - 'application/pdf' => 'pdf', - 'application/x-pdf' => 'pdf', - 'application/pgp-encrypted' => '7bit', - 'application/pgp-keys' => '7bit', - 'application/pgp-signature' => 'sig', - 'application/pkcs10' => 'p10', - 'application/pkcs7-mime' => 'p7m', - 'application/pkcs7-signature' => 'p7s', - 'application/pkix-cert' => 'cer', - 'application/pkix-crl' => 'crl', - 'application/pkix-pkipath' => 'pkipath', - 'application/pkixcmp' => 'pki', - 'application/postscript' => 'ps', - 'application/presentations' => 'shw', - 'application/prs.cww' => 'cw', - 'application/prs.nprend' => 'rnd', - 'application/quest' => 'qrt', - 'application/rtf' => 'rtf', - 'application/sgml-open-catalog' => 'soc', - 'application/sieve' => 'siv', - 'application/smil' => 'smi', - 'application/toolbook' => 'tbk', - 'application/vnd.3gpp.pic-bw-large' => 'plb', - 'application/vnd.3gpp.pic-bw-small' => 'psb', - 'application/vnd.3gpp.pic-bw-var' => 'pvb', - 'application/vnd.3gpp.sms' => 'sms', - 'application/vnd.acucorp' => 'atc', - 'application/vnd.adobe.xfdf' => 'xfdf', - 'application/vnd.amiga.amu' => 'ami', - 'application/vnd.blueice.multipass' => 'mpm', - 'application/vnd.cinderella' => 'cdy', - 'application/vnd.cosmocaller' => 'cmc', - 'application/vnd.criticaltools.wbs+xml' => 'wbs', - 'application/vnd.curl' => 'curl', - 'application/vnd.data-vision.rdz' => 'rdz', - 'application/vnd.dreamfactory' => 'dfac', - 'application/vnd.fsc.weblaunch' => 'fsc', - 'application/vnd.genomatix.tuxedo' => 'txd', - 'application/vnd.hbci' => 'hbci', - 'application/vnd.hhe.lesson-player' => 'les', - 'application/vnd.hp-hpgl' => 'plt', - 'application/vnd.ibm.electronic-media' => 'emm', - 'application/vnd.ibm.rights-management' => 'irm', - 'application/vnd.ibm.secure-container' => 'sc', - 'application/vnd.ipunplugged.rcprofile' => 'rcprofile', - 'application/vnd.irepository.package+xml' => 'irp', - 'application/vnd.jisp' => 'jisp', - 'application/vnd.kde.karbon' => 'karbon', - 'application/vnd.kde.kchart' => 'chrt', - 'application/vnd.kde.kformula' => 'kfo', - 'application/vnd.kde.kivio' => 'flw', - 'application/vnd.kde.kontour' => 'kon', - 'application/vnd.kde.kpresenter' => 'kpr', - 'application/vnd.kde.kspread' => 'ksp', - 'application/vnd.kde.kword' => 'kwd', - 'application/vnd.kenameapp' => 'htke', - 'application/vnd.kidspiration' => 'kia', - 'application/vnd.kinar' => 'kne', - 'application/vnd.llamagraphics.life-balance.desktop' => 'lbd', - 'application/vnd.llamagraphics.life-balance.exchange+xml' => 'lbe', - 'application/vnd.lotus-1-2-3' => 'wks', - 'application/vnd.mcd' => 'mcd', - 'application/vnd.mfmp' => 'mfm', - 'application/vnd.micrografx.flo' => 'flo', - 'application/vnd.micrografx.igx' => 'igx', - 'application/vnd.mif' => 'mif', - 'application/vnd.mophun.application' => 'mpn', - 'application/vnd.mophun.certificate' => 'mpc', - 'application/vnd.mozilla.xul+xml' => 'xul', - 'application/vnd.ms-artgalry' => 'cil', - 'application/vnd.ms-asf' => 'asf', - 'application/vnd.ms-excel' => 'xls', - 'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm', - 'application/vnd.ms-lrm' => 'lrm', - 'application/vnd.ms-powerpoint' => 'ppt', - 'application/vnd.ms-project' => 'mpp', - 'application/vnd.ms-tnef' => 'base64', - 'application/vnd.ms-works' => 'base64', - 'application/vnd.ms-wpl' => 'wpl', - 'application/vnd.mseq' => 'mseq', - 'application/vnd.nervana' => 'ent', - 'application/vnd.nokia.radio-preset' => 'rpst', - 'application/vnd.nokia.radio-presets' => 'rpss', - 'application/vnd.oasis.opendocument.text' => 'odt', - 'application/vnd.oasis.opendocument.text-template' => 'ott', - 'application/vnd.oasis.opendocument.text-web' => 'oth', - 'application/vnd.oasis.opendocument.text-master' => 'odm', - 'application/vnd.oasis.opendocument.graphics' => 'odg', - 'application/vnd.oasis.opendocument.graphics-template' => 'otg', - 'application/vnd.oasis.opendocument.presentation' => 'odp', - 'application/vnd.oasis.opendocument.presentation-template' => 'otp', - 'application/vnd.oasis.opendocument.spreadsheet' => 'ods', - 'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots', - 'application/vnd.oasis.opendocument.chart' => 'odc', - 'application/vnd.oasis.opendocument.formula' => 'odf', - 'application/vnd.oasis.opendocument.database' => 'odb', - 'application/vnd.oasis.opendocument.image' => 'odi', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', - 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx', - 'application/vnd.palm' => 'prc', - 'application/vnd.picsel' => 'efif', - 'application/vnd.pvi.ptid1' => 'pti', - 'application/vnd.quark.quarkxpress' => 'qxd', - 'application/vnd.sealed.doc' => 'sdoc', - 'application/vnd.sealed.eml' => 'seml', - 'application/vnd.sealed.mht' => 'smht', - 'application/vnd.sealed.ppt' => 'sppt', - 'application/vnd.sealed.xls' => 'sxls', - 'application/vnd.sealedmedia.softseal.html' => 'stml', - 'application/vnd.sealedmedia.softseal.pdf' => 'spdf', - 'application/vnd.seemail' => 'see', - 'application/vnd.smaf' => 'mmf', - 'application/vnd.sun.xml.calc' => 'sxc', - 'application/vnd.sun.xml.calc.template' => 'stc', - 'application/vnd.sun.xml.draw' => 'sxd', - 'application/vnd.sun.xml.draw.template' => 'std', - 'application/vnd.sun.xml.impress' => 'sxi', - 'application/vnd.sun.xml.impress.template' => 'sti', - 'application/vnd.sun.xml.math' => 'sxm', - 'application/vnd.sun.xml.writer' => 'sxw', - 'application/vnd.sun.xml.writer.global' => 'sxg', - 'application/vnd.sun.xml.writer.template' => 'stw', - 'application/vnd.sus-calendar' => 'sus', - 'application/vnd.vidsoft.vidconference' => 'vsc', - 'application/vnd.visio' => 'vsd', - 'application/vnd.visionary' => 'vis', - 'application/vnd.wap.sic' => 'sic', - 'application/vnd.wap.slc' => 'slc', - 'application/vnd.wap.wbxml' => 'wbxml', - 'application/vnd.wap.wmlc' => 'wmlc', - 'application/vnd.wap.wmlscriptc' => 'wmlsc', - 'application/vnd.webturbo' => 'wtb', - 'application/vnd.wordperfect' => 'wpd', - 'application/vnd.wqd' => 'wqd', - 'application/vnd.wv.csp+wbxml' => 'wv', - 'application/vnd.wv.csp+xml' => '8bit', - 'application/vnd.wv.ssp+xml' => '8bit', - 'application/vnd.yamaha.hv-dic' => 'hvd', - 'application/vnd.yamaha.hv-script' => 'hvs', - 'application/vnd.yamaha.hv-voice' => 'hvp', - 'application/vnd.yamaha.smaf-audio' => 'saf', - 'application/vnd.yamaha.smaf-phrase' => 'spf', - 'application/vocaltec-media-desc' => 'vmd', - 'application/vocaltec-media-file' => 'vmf', - 'application/vocaltec-talker' => 'vtk', - 'application/watcherinfo+xml' => 'wif', - 'application/wordperfect5.1' => 'wp5', - 'application/x-123' => 'wk', - 'application/x-7th_level_event' => '7ls', - 'application/x-authorware-bin' => 'aab', - 'application/x-authorware-map' => 'aam', - 'application/x-authorware-seg' => 'aas', - 'application/x-bcpio' => 'bcpio', - 'application/x-bleeper' => 'bleep', - 'application/x-bzip2' => 'bz2', - 'application/x-cdlink' => 'vcd', - 'application/x-chat' => 'chat', - 'application/x-chess-pgn' => 'pgn', - 'application/x-compress' => 'z', - 'application/x-cpio' => 'cpio', - 'application/x-cprplayer' => 'pqf', - 'application/x-csh' => 'csh', - 'application/x-cu-seeme' => 'csm', - 'application/x-cult3d-object' => 'co', - 'application/x-debian-package' => 'deb', - 'application/x-director' => 'dcr', - 'application/x-dvi' => 'dvi', - 'application/x-envoy' => 'evy', - 'application/x-futuresplash' => 'spl', - 'application/x-gtar' => 'gtar', - 'application/x-gzip' => 'gz', - 'application/x-hdf' => 'hdf', - 'application/x-hep' => 'hep', - 'application/x-html+ruby' => 'rhtml', - 'application/x-httpd-miva' => 'mv', - 'application/x-httpd-php' => 'phtml', - 'application/x-ica' => 'ica', - 'application/x-imagemap' => 'imagemap', - 'application/x-ipix' => 'ipx', - 'application/x-ipscript' => 'ips', - 'application/x-java-archive' => 'jar', - 'application/x-java-jnlp-file' => 'jnlp', - 'application/x-java-serialized-object' => 'ser', - 'application/x-java-vm' => 'class', - 'application/x-javascript' => 'js', - 'application/x-koan' => 'skp', - 'application/x-latex' => 'latex', - 'application/x-mac-compactpro' => 'cpt', - 'application/x-maker' => 'frm', - 'application/x-mathcad' => 'mcd', - 'application/x-midi' => 'mid', - 'application/x-mif' => 'mif', - 'application/x-msaccess' => 'mda', - 'application/x-msdos-program' => 'com', - 'application/x-msdownload' => 'base64', - 'application/x-msexcel' => 'xls', - 'application/x-msword' => 'doc', - 'application/x-netcdf' => 'nc', - 'application/x-ns-proxy-autoconfig' => 'pac', - 'application/x-pagemaker' => 'pm5', - 'application/x-perl' => 'pl', - 'application/x-pn-realmedia' => 'rp', - 'application/x-python' => 'py', - 'application/x-quicktimeplayer' => 'qtl', - 'application/x-rar-compressed' => 'rar', - 'application/x-ruby' => 'rb', - 'application/x-sh' => 'sh', - 'application/x-shar' => 'shar', - 'application/x-shockwave-flash' => 'swf', - 'application/x-sprite' => 'spr', - 'application/x-spss' => 'sav', - 'application/x-spt' => 'spt', - 'application/x-stuffit' => 'sit', - 'application/x-sv4cpio' => 'sv4cpio', - 'application/x-sv4crc' => 'sv4crc', - 'application/x-tar' => 'tar', - 'application/x-tcl' => 'tcl', - 'application/x-tex' => 'tex', - 'application/x-texinfo' => 'texinfo', - 'application/x-troff' => 't', - 'application/x-troff-man' => 'man', - 'application/x-troff-me' => 'me', - 'application/x-troff-ms' => 'ms', - 'application/x-twinvq' => 'vqf', - 'application/x-twinvq-plugin' => 'vqe', - 'application/x-ustar' => 'ustar', - 'application/x-vmsbackup' => 'bck', - 'application/x-wais-source' => 'src', - 'application/x-wingz' => 'wz', - 'application/x-word' => 'base64', - 'application/x-wordperfect6.1' => 'wp6', - 'application/x-x509-ca-cert' => 'crt', - 'application/x-zip-compressed' => 'zip', - 'application/xhtml+xml' => 'xhtml', - 'application/zip' => 'zip', - 'audio/3gpp' => '3gpp', - 'audio/amr' => 'amr', - 'audio/amr-wb' => 'awb', - 'audio/basic' => 'au', - 'audio/evrc' => 'evc', - 'audio/l16' => 'l16', - 'audio/midi' => 'mid', - 'audio/mpeg' => 'mp3', - 'audio/prs.sid' => 'sid', - 'audio/qcelp' => 'qcp', - 'audio/smv' => 'smv', - 'audio/vnd.audiokoz' => 'koz', - 'audio/vnd.digital-winds' => 'eol', - 'audio/vnd.everad.plj' => 'plj', - 'audio/vnd.lucent.voice' => 'lvp', - 'audio/vnd.nokia.mobile-xmf' => 'mxmf', - 'audio/vnd.nortel.vbk' => 'vbk', - 'audio/vnd.nuera.ecelp4800' => 'ecelp4800', - 'audio/vnd.nuera.ecelp7470' => 'ecelp7470', - 'audio/vnd.nuera.ecelp9600' => 'ecelp9600', - 'audio/vnd.sealedmedia.softseal.mpeg' => 'smp3', - 'audio/voxware' => 'vox', - 'audio/x-aiff' => 'aif', - 'audio/x-mid' => 'mid', - 'audio/x-midi' => 'mid', - 'audio/x-mpeg' => 'mp2', - 'audio/x-mpegurl' => 'mpu', - 'audio/x-pn-realaudio' => 'rm', - 'audio/x-pn-realaudio-plugin' => 'rpm', - 'audio/x-realaudio' => 'ra', - 'audio/x-wav' => 'wav', - 'chemical/x-csml' => 'csm', - 'chemical/x-embl-dl-nucleotide' => 'emb', - 'chemical/x-gaussian-cube' => 'cube', - 'chemical/x-gaussian-input' => 'gau', - 'chemical/x-jcamp-dx' => 'jdx', - 'chemical/x-mdl-molfile' => 'mol', - 'chemical/x-mdl-rxnfile' => 'rxn', - 'chemical/x-mdl-tgf' => 'tgf', - 'chemical/x-mopac-input' => 'mop', - 'chemical/x-pdb' => 'pdb', - 'chemical/x-rasmol' => 'scr', - 'chemical/x-xyz' => 'xyz', - 'drawing/dwf' => 'dwf', - 'drawing/x-dwf' => 'dwf', - 'i-world/i-vrml' => 'ivr', - 'image/bmp' => 'bmp', - 'image/cewavelet' => 'wif', - 'image/cis-cod' => 'cod', - 'image/fif' => 'fif', - 'image/gif' => 'gif', - 'image/ief' => 'ief', - 'image/jp2' => 'jp2', - 'image/jpeg' => 'jpg', - 'image/jpm' => 'jpm', - 'image/jpx' => 'jpf', - 'image/pict' => 'pic', - 'image/pjpeg' => 'jpg', - 'image/png' => 'png', - 'image/targa' => 'tga', - 'image/tiff' => 'tif', - 'image/vn-svf' => 'svf', - 'image/vnd.dgn' => 'dgn', - 'image/vnd.djvu' => 'djvu', - 'image/vnd.dwg' => 'dwg', - 'image/vnd.glocalgraphics.pgb' => 'pgb', - 'image/vnd.microsoft.icon' => 'ico', - 'image/vnd.ms-modi' => 'mdi', - 'image/vnd.sealed.png' => 'spng', - 'image/vnd.sealedmedia.softseal.gif' => 'sgif', - 'image/vnd.sealedmedia.softseal.jpg' => 'sjpg', - 'image/vnd.wap.wbmp' => 'wbmp', - 'image/x-bmp' => 'bmp', - 'image/x-cmu-raster' => 'ras', - 'image/x-freehand' => 'fh4', - 'image/x-png' => 'png', - 'image/x-portable-anymap' => 'pnm', - 'image/x-portable-bitmap' => 'pbm', - 'image/x-portable-graymap' => 'pgm', - 'image/x-portable-pixmap' => 'ppm', - 'image/x-rgb' => 'rgb', - 'image/x-xbitmap' => 'xbm', - 'image/x-xpixmap' => 'xpm', - 'image/x-xwindowdump' => 'xwd', - 'message/external-body' => '8bit', - 'message/news' => '8bit', - 'message/partial' => '8bit', - 'message/rfc822' => '8bit', - 'model/iges' => 'igs', - 'model/mesh' => 'msh', - 'model/vnd.parasolid.transmit.binary' => 'x_b', - 'model/vnd.parasolid.transmit.text' => 'x_t', - 'model/vrml' => 'wrl', - 'multipart/alternative' => '8bit', - 'multipart/appledouble' => '8bit', - 'multipart/digest' => '8bit', - 'multipart/mixed' => '8bit', - 'multipart/parallel' => '8bit', - 'text/comma-separated-values' => 'csv', - 'text/css' => 'css', - 'text/html' => 'html', - 'text/plain' => 'txt', - 'text/prs.fallenstein.rst' => 'rst', - 'text/richtext' => 'rtx', - 'text/rtf' => 'rtf', - 'text/sgml' => 'sgml', - 'text/tab-separated-values' => 'tsv', - 'text/vnd.net2phone.commcenter.command' => 'ccc', - 'text/vnd.sun.j2me.app-descriptor' => 'jad', - 'text/vnd.wap.si' => 'si', - 'text/vnd.wap.sl' => 'sl', - 'text/vnd.wap.wml' => 'wml', - 'text/vnd.wap.wmlscript' => 'wmls', - 'text/x-hdml' => 'hdml', - 'text/x-setext' => 'etx', - 'text/x-sgml' => 'sgml', - 'text/x-speech' => 'talk', - 'text/x-vcalendar' => 'vcs', - 'text/x-vcard' => 'vcf', - 'text/xml' => 'xml', - 'ulead/vrml' => 'uvr', - 'video/3gpp' => '3gp', - 'video/dl' => 'dl', - 'video/gl' => 'gl', - 'video/mj2' => 'mj2', - 'video/mpeg' => 'mpeg', - 'video/quicktime' => 'mov', - 'video/vdo' => 'vdo', - 'video/vivo' => 'viv', - 'video/vnd.fvt' => 'fvt', - 'video/vnd.mpegurl' => 'mxu', - 'video/vnd.nokia.interleaved-multimedia' => 'nim', - 'video/vnd.objectvideo' => 'mp4', - 'video/vnd.sealed.mpeg1' => 's11', - 'video/vnd.sealed.mpeg4' => 'smpg', - 'video/vnd.sealed.swf' => 'sswf', - 'video/vnd.sealedmedia.softseal.mov' => 'smov', - 'video/vnd.vivo' => 'vivo', - 'video/x-fli' => 'fli', - 'video/x-ms-asf' => 'asf', - 'video/x-ms-wmv' => 'wmv', - 'video/x-msvideo' => 'avi', - 'video/x-sgi-movie' => 'movie', - 'x-chemical/x-pdb' => 'pdb', - 'x-chemical/x-xyz' => 'xyz', - 'x-conference/x-cooltalk' => 'ice', - 'x-drawing/dwf' => 'dwf', - 'x-world/x-d96' => 'd', - 'x-world/x-svr' => 'svr', - 'x-world/x-vream' => 'vrw', - 'x-world/x-vrml' => 'wrl', - ); + protected $guessers = array(); + + /** + * Returns the singleton instance + * + * @return ExtensionGuesser + */ + static public function getInstance() + { + if (null === self::$instance) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Registers all natively provided extension guessers + */ + private function __construct() + { + $this->register(new MimeTypeExtensionGuesser()); + } /** - * Returns the extension based on the mime type. + * Registers a new extension guesser * - * If the mime type is unknown, returns null. + * When guessing, this guesser is preferred over previously registered ones. * - * @return string|null The guessed extension or null if it cannot be guessed + * @param ExtensionGuesserInterface $guesser */ - static function guessExtension($mimeType) + public function register(ExtensionGuesserInterface $guesser) { - return isset(static::$defaultExtensions[$mimeType]) ? static::$defaultExtensions[$mimeType] : null; + array_unshift($this->guessers, $guesser); } + /** + * Tries to guess the extension + * + * The mime type 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. + * + * @param string $mimeType The mime type + * @return string The guessed extension or NULL, if none could be guessed + */ + public function guess($mimeType) + { + foreach ($this->guessers as $guesser) { + $extension = $guesser->guess($mimeType); + + if (null !== $extension) { + break; + } + } + + return $extension; + } } diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesserInterface.php b/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesserInterface.php new file mode 100644 index 0000000000000..a55124814e80b --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesserInterface.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation\File\MimeType; + +/** + * Guesses the file extension corresponding to a given mime type + */ +interface ExtensionGuesserInterface +{ + /** + * Makes a best guess for a file extension, given a mime type + * + * @param string $mimeType The mime type + * @return string The guessed extension or NULL, if none could be guessed + */ + function guess($mimeType); + +} diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeExtensionGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeExtensionGuesser.php new file mode 100644 index 0000000000000..3efa93e4905a8 --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeExtensionGuesser.php @@ -0,0 +1,449 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation\File\Mimetype; + +/** + * Provides a best-guess mapping of mime type to file extension. + */ +class MimeTypeExtensionGuesser implements ExtensionGuesserInterface +{ + /** + * A map of mime types and their default extensions. + * + * @var array + */ + protected $defaultExtensions = array( + 'application/andrew-inset' => 'ez', + 'application/appledouble' => 'base64', + 'application/applefile' => 'base64', + 'application/commonground' => 'dp', + 'application/cprplayer' => 'pqi', + 'application/dsptype' => 'tsp', + 'application/excel' => 'xls', + 'application/font-tdpfr' => 'pfr', + 'application/futuresplash' => 'spl', + 'application/hstu' => 'stk', + 'application/hyperstudio' => 'stk', + 'application/javascript' => 'js', + 'application/mac-binhex40' => 'hqx', + 'application/mac-compactpro' => 'cpt', + 'application/mbed' => 'mbd', + 'application/mirage' => 'mfp', + 'application/msword' => 'doc', + 'application/ocsp-request' => 'orq', + 'application/ocsp-response' => 'ors', + 'application/octet-stream' => 'bin', + 'application/oda' => 'oda', + 'application/ogg' => 'ogg', + 'application/pdf' => 'pdf', + 'application/x-pdf' => 'pdf', + 'application/pgp-encrypted' => '7bit', + 'application/pgp-keys' => '7bit', + 'application/pgp-signature' => 'sig', + 'application/pkcs10' => 'p10', + 'application/pkcs7-mime' => 'p7m', + 'application/pkcs7-signature' => 'p7s', + 'application/pkix-cert' => 'cer', + 'application/pkix-crl' => 'crl', + 'application/pkix-pkipath' => 'pkipath', + 'application/pkixcmp' => 'pki', + 'application/postscript' => 'ps', + 'application/presentations' => 'shw', + 'application/prs.cww' => 'cw', + 'application/prs.nprend' => 'rnd', + 'application/quest' => 'qrt', + 'application/rtf' => 'rtf', + 'application/sgml-open-catalog' => 'soc', + 'application/sieve' => 'siv', + 'application/smil' => 'smi', + 'application/toolbook' => 'tbk', + 'application/vnd.3gpp.pic-bw-large' => 'plb', + 'application/vnd.3gpp.pic-bw-small' => 'psb', + 'application/vnd.3gpp.pic-bw-var' => 'pvb', + 'application/vnd.3gpp.sms' => 'sms', + 'application/vnd.acucorp' => 'atc', + 'application/vnd.adobe.xfdf' => 'xfdf', + 'application/vnd.amiga.amu' => 'ami', + 'application/vnd.blueice.multipass' => 'mpm', + 'application/vnd.cinderella' => 'cdy', + 'application/vnd.cosmocaller' => 'cmc', + 'application/vnd.criticaltools.wbs+xml' => 'wbs', + 'application/vnd.curl' => 'curl', + 'application/vnd.data-vision.rdz' => 'rdz', + 'application/vnd.dreamfactory' => 'dfac', + 'application/vnd.fsc.weblaunch' => 'fsc', + 'application/vnd.genomatix.tuxedo' => 'txd', + 'application/vnd.hbci' => 'hbci', + 'application/vnd.hhe.lesson-player' => 'les', + 'application/vnd.hp-hpgl' => 'plt', + 'application/vnd.ibm.electronic-media' => 'emm', + 'application/vnd.ibm.rights-management' => 'irm', + 'application/vnd.ibm.secure-container' => 'sc', + 'application/vnd.ipunplugged.rcprofile' => 'rcprofile', + 'application/vnd.irepository.package+xml' => 'irp', + 'application/vnd.jisp' => 'jisp', + 'application/vnd.kde.karbon' => 'karbon', + 'application/vnd.kde.kchart' => 'chrt', + 'application/vnd.kde.kformula' => 'kfo', + 'application/vnd.kde.kivio' => 'flw', + 'application/vnd.kde.kontour' => 'kon', + 'application/vnd.kde.kpresenter' => 'kpr', + 'application/vnd.kde.kspread' => 'ksp', + 'application/vnd.kde.kword' => 'kwd', + 'application/vnd.kenameapp' => 'htke', + 'application/vnd.kidspiration' => 'kia', + 'application/vnd.kinar' => 'kne', + 'application/vnd.llamagraphics.life-balance.desktop' => 'lbd', + 'application/vnd.llamagraphics.life-balance.exchange+xml' => 'lbe', + 'application/vnd.lotus-1-2-3' => 'wks', + 'application/vnd.mcd' => 'mcd', + 'application/vnd.mfmp' => 'mfm', + 'application/vnd.micrografx.flo' => 'flo', + 'application/vnd.micrografx.igx' => 'igx', + 'application/vnd.mif' => 'mif', + 'application/vnd.mophun.application' => 'mpn', + 'application/vnd.mophun.certificate' => 'mpc', + 'application/vnd.mozilla.xul+xml' => 'xul', + 'application/vnd.ms-artgalry' => 'cil', + 'application/vnd.ms-asf' => 'asf', + 'application/vnd.ms-excel' => 'xls', + 'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm', + 'application/vnd.ms-lrm' => 'lrm', + 'application/vnd.ms-powerpoint' => 'ppt', + 'application/vnd.ms-project' => 'mpp', + 'application/vnd.ms-tnef' => 'base64', + 'application/vnd.ms-works' => 'base64', + 'application/vnd.ms-wpl' => 'wpl', + 'application/vnd.mseq' => 'mseq', + 'application/vnd.nervana' => 'ent', + 'application/vnd.nokia.radio-preset' => 'rpst', + 'application/vnd.nokia.radio-presets' => 'rpss', + 'application/vnd.oasis.opendocument.text' => 'odt', + 'application/vnd.oasis.opendocument.text-template' => 'ott', + 'application/vnd.oasis.opendocument.text-web' => 'oth', + 'application/vnd.oasis.opendocument.text-master' => 'odm', + 'application/vnd.oasis.opendocument.graphics' => 'odg', + 'application/vnd.oasis.opendocument.graphics-template' => 'otg', + 'application/vnd.oasis.opendocument.presentation' => 'odp', + 'application/vnd.oasis.opendocument.presentation-template' => 'otp', + 'application/vnd.oasis.opendocument.spreadsheet' => 'ods', + 'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots', + 'application/vnd.oasis.opendocument.chart' => 'odc', + 'application/vnd.oasis.opendocument.formula' => 'odf', + 'application/vnd.oasis.opendocument.database' => 'odb', + 'application/vnd.oasis.opendocument.image' => 'odi', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', + 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx', + 'application/vnd.palm' => 'prc', + 'application/vnd.picsel' => 'efif', + 'application/vnd.pvi.ptid1' => 'pti', + 'application/vnd.quark.quarkxpress' => 'qxd', + 'application/vnd.sealed.doc' => 'sdoc', + 'application/vnd.sealed.eml' => 'seml', + 'application/vnd.sealed.mht' => 'smht', + 'application/vnd.sealed.ppt' => 'sppt', + 'application/vnd.sealed.xls' => 'sxls', + 'application/vnd.sealedmedia.softseal.html' => 'stml', + 'application/vnd.sealedmedia.softseal.pdf' => 'spdf', + 'application/vnd.seemail' => 'see', + 'application/vnd.smaf' => 'mmf', + 'application/vnd.sun.xml.calc' => 'sxc', + 'application/vnd.sun.xml.calc.template' => 'stc', + 'application/vnd.sun.xml.draw' => 'sxd', + 'application/vnd.sun.xml.draw.template' => 'std', + 'application/vnd.sun.xml.impress' => 'sxi', + 'application/vnd.sun.xml.impress.template' => 'sti', + 'application/vnd.sun.xml.math' => 'sxm', + 'application/vnd.sun.xml.writer' => 'sxw', + 'application/vnd.sun.xml.writer.global' => 'sxg', + 'application/vnd.sun.xml.writer.template' => 'stw', + 'application/vnd.sus-calendar' => 'sus', + 'application/vnd.vidsoft.vidconference' => 'vsc', + 'application/vnd.visio' => 'vsd', + 'application/vnd.visionary' => 'vis', + 'application/vnd.wap.sic' => 'sic', + 'application/vnd.wap.slc' => 'slc', + 'application/vnd.wap.wbxml' => 'wbxml', + 'application/vnd.wap.wmlc' => 'wmlc', + 'application/vnd.wap.wmlscriptc' => 'wmlsc', + 'application/vnd.webturbo' => 'wtb', + 'application/vnd.wordperfect' => 'wpd', + 'application/vnd.wqd' => 'wqd', + 'application/vnd.wv.csp+wbxml' => 'wv', + 'application/vnd.wv.csp+xml' => '8bit', + 'application/vnd.wv.ssp+xml' => '8bit', + 'application/vnd.yamaha.hv-dic' => 'hvd', + 'application/vnd.yamaha.hv-script' => 'hvs', + 'application/vnd.yamaha.hv-voice' => 'hvp', + 'application/vnd.yamaha.smaf-audio' => 'saf', + 'application/vnd.yamaha.smaf-phrase' => 'spf', + 'application/vocaltec-media-desc' => 'vmd', + 'application/vocaltec-media-file' => 'vmf', + 'application/vocaltec-talker' => 'vtk', + 'application/watcherinfo+xml' => 'wif', + 'application/wordperfect5.1' => 'wp5', + 'application/x-123' => 'wk', + 'application/x-7th_level_event' => '7ls', + 'application/x-authorware-bin' => 'aab', + 'application/x-authorware-map' => 'aam', + 'application/x-authorware-seg' => 'aas', + 'application/x-bcpio' => 'bcpio', + 'application/x-bleeper' => 'bleep', + 'application/x-bzip2' => 'bz2', + 'application/x-cdlink' => 'vcd', + 'application/x-chat' => 'chat', + 'application/x-chess-pgn' => 'pgn', + 'application/x-compress' => 'z', + 'application/x-cpio' => 'cpio', + 'application/x-cprplayer' => 'pqf', + 'application/x-csh' => 'csh', + 'application/x-cu-seeme' => 'csm', + 'application/x-cult3d-object' => 'co', + 'application/x-debian-package' => 'deb', + 'application/x-director' => 'dcr', + 'application/x-dvi' => 'dvi', + 'application/x-envoy' => 'evy', + 'application/x-futuresplash' => 'spl', + 'application/x-gtar' => 'gtar', + 'application/x-gzip' => 'gz', + 'application/x-hdf' => 'hdf', + 'application/x-hep' => 'hep', + 'application/x-html+ruby' => 'rhtml', + 'application/x-httpd-miva' => 'mv', + 'application/x-httpd-php' => 'phtml', + 'application/x-ica' => 'ica', + 'application/x-imagemap' => 'imagemap', + 'application/x-ipix' => 'ipx', + 'application/x-ipscript' => 'ips', + 'application/x-java-archive' => 'jar', + 'application/x-java-jnlp-file' => 'jnlp', + 'application/x-java-serialized-object' => 'ser', + 'application/x-java-vm' => 'class', + 'application/x-javascript' => 'js', + 'application/x-koan' => 'skp', + 'application/x-latex' => 'latex', + 'application/x-mac-compactpro' => 'cpt', + 'application/x-maker' => 'frm', + 'application/x-mathcad' => 'mcd', + 'application/x-midi' => 'mid', + 'application/x-mif' => 'mif', + 'application/x-msaccess' => 'mda', + 'application/x-msdos-program' => 'com', + 'application/x-msdownload' => 'base64', + 'application/x-msexcel' => 'xls', + 'application/x-msword' => 'doc', + 'application/x-netcdf' => 'nc', + 'application/x-ns-proxy-autoconfig' => 'pac', + 'application/x-pagemaker' => 'pm5', + 'application/x-perl' => 'pl', + 'application/x-pn-realmedia' => 'rp', + 'application/x-python' => 'py', + 'application/x-quicktimeplayer' => 'qtl', + 'application/x-rar-compressed' => 'rar', + 'application/x-ruby' => 'rb', + 'application/x-sh' => 'sh', + 'application/x-shar' => 'shar', + 'application/x-shockwave-flash' => 'swf', + 'application/x-sprite' => 'spr', + 'application/x-spss' => 'sav', + 'application/x-spt' => 'spt', + 'application/x-stuffit' => 'sit', + 'application/x-sv4cpio' => 'sv4cpio', + 'application/x-sv4crc' => 'sv4crc', + 'application/x-tar' => 'tar', + 'application/x-tcl' => 'tcl', + 'application/x-tex' => 'tex', + 'application/x-texinfo' => 'texinfo', + 'application/x-troff' => 't', + 'application/x-troff-man' => 'man', + 'application/x-troff-me' => 'me', + 'application/x-troff-ms' => 'ms', + 'application/x-twinvq' => 'vqf', + 'application/x-twinvq-plugin' => 'vqe', + 'application/x-ustar' => 'ustar', + 'application/x-vmsbackup' => 'bck', + 'application/x-wais-source' => 'src', + 'application/x-wingz' => 'wz', + 'application/x-word' => 'base64', + 'application/x-wordperfect6.1' => 'wp6', + 'application/x-x509-ca-cert' => 'crt', + 'application/x-zip-compressed' => 'zip', + 'application/xhtml+xml' => 'xhtml', + 'application/zip' => 'zip', + 'audio/3gpp' => '3gpp', + 'audio/amr' => 'amr', + 'audio/amr-wb' => 'awb', + 'audio/basic' => 'au', + 'audio/evrc' => 'evc', + 'audio/l16' => 'l16', + 'audio/midi' => 'mid', + 'audio/mpeg' => 'mp3', + 'audio/prs.sid' => 'sid', + 'audio/qcelp' => 'qcp', + 'audio/smv' => 'smv', + 'audio/vnd.audiokoz' => 'koz', + 'audio/vnd.digital-winds' => 'eol', + 'audio/vnd.everad.plj' => 'plj', + 'audio/vnd.lucent.voice' => 'lvp', + 'audio/vnd.nokia.mobile-xmf' => 'mxmf', + 'audio/vnd.nortel.vbk' => 'vbk', + 'audio/vnd.nuera.ecelp4800' => 'ecelp4800', + 'audio/vnd.nuera.ecelp7470' => 'ecelp7470', + 'audio/vnd.nuera.ecelp9600' => 'ecelp9600', + 'audio/vnd.sealedmedia.softseal.mpeg' => 'smp3', + 'audio/voxware' => 'vox', + 'audio/x-aiff' => 'aif', + 'audio/x-mid' => 'mid', + 'audio/x-midi' => 'mid', + 'audio/x-mpeg' => 'mp2', + 'audio/x-mpegurl' => 'mpu', + 'audio/x-pn-realaudio' => 'rm', + 'audio/x-pn-realaudio-plugin' => 'rpm', + 'audio/x-realaudio' => 'ra', + 'audio/x-wav' => 'wav', + 'chemical/x-csml' => 'csm', + 'chemical/x-embl-dl-nucleotide' => 'emb', + 'chemical/x-gaussian-cube' => 'cube', + 'chemical/x-gaussian-input' => 'gau', + 'chemical/x-jcamp-dx' => 'jdx', + 'chemical/x-mdl-molfile' => 'mol', + 'chemical/x-mdl-rxnfile' => 'rxn', + 'chemical/x-mdl-tgf' => 'tgf', + 'chemical/x-mopac-input' => 'mop', + 'chemical/x-pdb' => 'pdb', + 'chemical/x-rasmol' => 'scr', + 'chemical/x-xyz' => 'xyz', + 'drawing/dwf' => 'dwf', + 'drawing/x-dwf' => 'dwf', + 'i-world/i-vrml' => 'ivr', + 'image/bmp' => 'bmp', + 'image/cewavelet' => 'wif', + 'image/cis-cod' => 'cod', + 'image/fif' => 'fif', + 'image/gif' => 'gif', + 'image/ief' => 'ief', + 'image/jp2' => 'jp2', + 'image/jpeg' => 'jpg', + 'image/jpm' => 'jpm', + 'image/jpx' => 'jpf', + 'image/pict' => 'pic', + 'image/pjpeg' => 'jpg', + 'image/png' => 'png', + 'image/targa' => 'tga', + 'image/tiff' => 'tif', + 'image/vn-svf' => 'svf', + 'image/vnd.dgn' => 'dgn', + 'image/vnd.djvu' => 'djvu', + 'image/vnd.dwg' => 'dwg', + 'image/vnd.glocalgraphics.pgb' => 'pgb', + 'image/vnd.microsoft.icon' => 'ico', + 'image/vnd.ms-modi' => 'mdi', + 'image/vnd.sealed.png' => 'spng', + 'image/vnd.sealedmedia.softseal.gif' => 'sgif', + 'image/vnd.sealedmedia.softseal.jpg' => 'sjpg', + 'image/vnd.wap.wbmp' => 'wbmp', + 'image/x-bmp' => 'bmp', + 'image/x-cmu-raster' => 'ras', + 'image/x-freehand' => 'fh4', + 'image/x-png' => 'png', + 'image/x-portable-anymap' => 'pnm', + 'image/x-portable-bitmap' => 'pbm', + 'image/x-portable-graymap' => 'pgm', + 'image/x-portable-pixmap' => 'ppm', + 'image/x-rgb' => 'rgb', + 'image/x-xbitmap' => 'xbm', + 'image/x-xpixmap' => 'xpm', + 'image/x-xwindowdump' => 'xwd', + 'message/external-body' => '8bit', + 'message/news' => '8bit', + 'message/partial' => '8bit', + 'message/rfc822' => '8bit', + 'model/iges' => 'igs', + 'model/mesh' => 'msh', + 'model/vnd.parasolid.transmit.binary' => 'x_b', + 'model/vnd.parasolid.transmit.text' => 'x_t', + 'model/vrml' => 'wrl', + 'multipart/alternative' => '8bit', + 'multipart/appledouble' => '8bit', + 'multipart/digest' => '8bit', + 'multipart/mixed' => '8bit', + 'multipart/parallel' => '8bit', + 'text/comma-separated-values' => 'csv', + 'text/css' => 'css', + 'text/html' => 'html', + 'text/plain' => 'txt', + 'text/prs.fallenstein.rst' => 'rst', + 'text/richtext' => 'rtx', + 'text/rtf' => 'rtf', + 'text/sgml' => 'sgml', + 'text/tab-separated-values' => 'tsv', + 'text/vnd.net2phone.commcenter.command' => 'ccc', + 'text/vnd.sun.j2me.app-descriptor' => 'jad', + 'text/vnd.wap.si' => 'si', + 'text/vnd.wap.sl' => 'sl', + 'text/vnd.wap.wml' => 'wml', + 'text/vnd.wap.wmlscript' => 'wmls', + 'text/x-hdml' => 'hdml', + 'text/x-setext' => 'etx', + 'text/x-sgml' => 'sgml', + 'text/x-speech' => 'talk', + 'text/x-vcalendar' => 'vcs', + 'text/x-vcard' => 'vcf', + 'text/xml' => 'xml', + 'ulead/vrml' => 'uvr', + 'video/3gpp' => '3gp', + 'video/dl' => 'dl', + 'video/gl' => 'gl', + 'video/mj2' => 'mj2', + 'video/mpeg' => 'mpeg', + 'video/quicktime' => 'mov', + 'video/vdo' => 'vdo', + 'video/vivo' => 'viv', + 'video/vnd.fvt' => 'fvt', + 'video/vnd.mpegurl' => 'mxu', + 'video/vnd.nokia.interleaved-multimedia' => 'nim', + 'video/vnd.objectvideo' => 'mp4', + 'video/vnd.sealed.mpeg1' => 's11', + 'video/vnd.sealed.mpeg4' => 'smpg', + 'video/vnd.sealed.swf' => 'sswf', + 'video/vnd.sealedmedia.softseal.mov' => 'smov', + 'video/vnd.vivo' => 'vivo', + 'video/x-fli' => 'fli', + 'video/x-ms-asf' => 'asf', + 'video/x-ms-wmv' => 'wmv', + 'video/x-msvideo' => 'avi', + 'video/x-sgi-movie' => 'movie', + 'x-chemical/x-pdb' => 'pdb', + 'x-chemical/x-xyz' => 'xyz', + 'x-conference/x-cooltalk' => 'ice', + 'x-drawing/dwf' => 'dwf', + 'x-world/x-d96' => 'd', + 'x-world/x-svr' => 'svr', + 'x-world/x-vream' => 'vrw', + 'x-world/x-vrml' => 'wrl', + ); + + /** + * Returns the extension based on the mime type. + * + * If the mime type is unknown, returns null. + * + * @return string|null The guessed extension or null if it cannot be guessed + */ + public function guess($mimeType) + { + return isset($this->defaultExtensions[$mimeType]) ? $this->defaultExtensions[$mimeType] : null; + } + +} From 34494b36a65b8de42b2542335ae890b5ba643b10 Mon Sep 17 00:00:00 2001 From: Brian King Date: Tue, 21 Jun 2011 15:43:43 +0200 Subject: [PATCH 006/196] whitespace fixes --- .../HttpFoundation/File/MimeType/ExtensionGuesserInterface.php | 1 - .../HttpFoundation/File/MimeType/MimeTypeExtensionGuesser.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesserInterface.php b/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesserInterface.php index a55124814e80b..5b14ef9ed3c47 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesserInterface.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/ExtensionGuesserInterface.php @@ -23,5 +23,4 @@ interface ExtensionGuesserInterface * @return string The guessed extension or NULL, if none could be guessed */ function guess($mimeType); - } diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeExtensionGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeExtensionGuesser.php index 3efa93e4905a8..188630bb760d9 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeExtensionGuesser.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeExtensionGuesser.php @@ -445,5 +445,4 @@ public function guess($mimeType) { return isset($this->defaultExtensions[$mimeType]) ? $this->defaultExtensions[$mimeType] : null; } - } From fea74dbf088c9f061032f03ad3c1dee1a3ea2238 Mon Sep 17 00:00:00 2001 From: stloyd Date: Sat, 9 Jul 2011 12:12:17 +0200 Subject: [PATCH 007/196] Added information page with better messages for Profiler --- .../Controller/ProfilerController.php | 29 +++++++++++--- .../Resources/config/routing/profiler.xml | 4 ++ .../Resources/views/Profiler/admin.html.twig | 14 ++++--- .../Resources/views/Profiler/info.html.twig | 39 +++++++++++++++++++ .../views/Profiler/notfound.html.twig | 2 +- 5 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/info.html.twig diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index b06e54eafbee0..476d0ee7331f4 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -87,7 +87,7 @@ public function purgeAction() $profiler->disable(); $profiler->purge(); - return new RedirectResponse($this->container->get('router')->generate('_profiler', array('token' => '-'))); + return new RedirectResponse($this->container->get('router')->generate('_profiler_info', array('about' => 'purge'))); } /** @@ -100,16 +100,35 @@ public function importAction() $profiler = $this->container->get('profiler'); $profiler->disable(); + $router = $this->container->get('router'); + $file = $this->container->get('request')->files->get('file'); - if (!$file || UPLOAD_ERR_OK !== $file->getError()) { - throw new \RuntimeException('Problem uploading the data.'); + if (!$file || !$file->isValid()) { + return new RedirectResponse($router->generate('_profiler_info', array('about' => 'upload_error'))); } if (!$profile = $profiler->import(file_get_contents($file->getPath()))) { - throw new \RuntimeException('Problem uploading the data (token already exists).'); + return new RedirectResponse($router->generate('_profiler_info', array('about' => 'already_exists'))); } - return new RedirectResponse($this->container->get('router')->generate('_profiler', array('token' => $profile->getToken()))); + return new RedirectResponse($router->generate('_profiler', array('token' => $profile->getToken()))); + } + + /** + * Displays information page. + * + * @param string $about + * + * @return Response A Response instance + */ + public function infoAction($about) + { + $profiler = $this->container->get('profiler'); + $profiler->disable(); + + return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:info.html.twig', array( + 'about' => $about + )); } /** diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml index 7c3d3232c03d5..e26c9300d9ca3 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml @@ -12,6 +12,10 @@ WebProfilerBundle:Profiler:purge + + WebProfilerBundle:Profiler:info + + WebProfilerBundle:Profiler:import diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/admin.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/admin.html.twig index c266ba3ff8d35..5f528c850d487 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/admin.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/admin.html.twig @@ -5,12 +5,14 @@
-
- » Purge -
-
- » Export -
+ {% if token is not empty %} +
+ » Purge +
+
+ » Export +
+ {% endif %} »