forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generated mimeType detection file from apache http mime.types file
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. see also yiisoft/yii#2851 and yiisoft/yii#2857
- Loading branch information
Showing
2 changed files
with
947 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?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 <[email protected]> | ||
* @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"); | ||
} | ||
} | ||
} |
Oops, something went wrong.