determine mime type by file extension, not by geshi type
[phorkie.git] / src / Phorkie / File.php
index 6e71de37ca6cfef60fa7d62372ffc1a95921fbec..bf2eb601d40b7d34d8c06a23dc0f18d7335aa8b4 100644 (file)
@@ -17,6 +17,11 @@ class File
      */
     public $repo;
 
+    /**
+     * Maps file extensions to MIME Types
+     *
+     * @var array
+     */
     public static $arMimeTypeMap = array(
         'css'  => 'text/css',
         'htm'  => 'text/html',
@@ -24,6 +29,17 @@ class File
         'js'   => 'application/javascript',
         'php'  => 'text/x-php',
         'txt'  => 'text/plain',
+        'xml'  => 'text/xml',
+    );
+
+    /**
+     * Maps file extensions to geshi types
+     *
+     * @var array
+     */
+    public static $arTypeMap = array(
+        'htm'  => 'xml',
+        'html' => 'xml',
     );
 
     public function __construct($path, Repository $repo)
@@ -43,15 +59,30 @@ class File
     }
 
     /**
-     * Returns the type of the file, as used internally by Phorkie
+     * Get file extension without dot
      *
      * @return string
      */
-    public function getType()
+    public function getExt()
     {
         return substr($this->path, strrpos($this->path, '.') + 1);
     }
 
+    /**
+     * Returns the type of the file, as used by Geshi
+     *
+     * @return string
+     */
+    public function getType()
+    {
+        $ext = $this->getExt();
+        if (isset(static::$arTypeMap[$ext])) {
+            $ext = static::$arTypeMap[$ext];
+        }
+
+        return $ext;
+    }
+
     public function getContent()
     {
         return file_get_contents($this->path);
@@ -72,11 +103,11 @@ class File
 
     public function getMimeType()
     {
-        $type = $this->getType();
-        if (!isset(static::$arMimeTypeMap[$type])) {
+        $ext = $this->getExt();
+        if (!isset(static::$arMimeTypeMap[$ext])) {
             return null;
         }
-        return static::$arMimeTypeMap[$type];
+        return static::$arMimeTypeMap[$ext];
     }
 
     /**