Commit 0b248dff by Carsten Brandt

Merge PR #3643 branch 'mime-types-from-apache' of github.com:yiisoft/yii2

* 'mime-types-from-apache' of github.com:yiisoft/yii2: changelog generated mimeType detection file from apache http mime.types file Conflicts: framework/CHANGELOG.md
parents 12a00d49 ac9a7c65
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\build\controllers;
use Yii;
use yii\console\Controller;
use yii\helpers\VarDumper;
/**
* MimeTypeController generates a map of file extensions to MIME types
*
* It uses `mime.types` file from apache http located under
* http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=markup
*
* This file has been placed in the public domain for unlimited redistribution,
* so we can use it and ship it with Yii.
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class MimeTypeController extends Controller
{
/**
* @param string $outFile the file to update. Defaults to @yii/helpers/mimeTypes.php
*/
public function actionIndex($outFile = null)
{
if ($outFile === null) {
$outFile = Yii::getAlias('@yii/helpers/mimeTypes.php');
}
if ($content = file_get_contents('http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co')) {
$mimeMap = [];
foreach(explode("\n", $content) as $line) {
$line = trim($line);
if (empty($line) || $line[0] == '#') { // skip comments and empty lines
continue;
}
$parts = preg_split('/\s+/', $line);
$mime = array_shift($parts);
foreach($parts as $ext) {
if (!empty($ext)) {
$mimeMap[$ext] = $mime;
}
}
}
ksort($mimeMap);
$array = VarDumper::export($mimeMap);
$content = <<<EOD
<?php
/**
* MIME types.
*
* This file contains most commonly used MIME types
* according to file extension names.
* Its content is generated from the apache http mime.types file.
* http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=markup
* This file has been placed in the public domain for unlimited redistribution.
*/
return $array;
EOD;
file_put_contents($outFile, $content);
} else {
$this->stderr("Failed to download mime.types file from apache SVN.\n");
}
}
}
......@@ -65,7 +65,8 @@ Yii Framework 2 Change Log
- Enh #3562: Adding rotateByCopy to yii\log\FileTarget (pawzar)
- Enh #3574: Add integrity check support for SQLite (zeeke)
- Enh #3597: Nested array support for HTML5 custom "data-*" attributes (armab)
- Enh #3607: Added support for limit in migrations actions: history, new, redo (Ragazzo)
- Enh #3607: Added support for specifying 'all' as limit in migration actions: history, new, redo (Ragazzo)
- Enh #3643: Improved Mime-Type detection by using the `mime.types` file from apache http project to dected mime types by file extension (cebe, pavel-voronin, trejder)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue)
- Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment