use pear data_dir if installed via package
authorChristian Weiske <[email protected]>
Tue, 5 Jun 2012 11:44:31 +0000 (13:44 +0200)
committerChristian Weiske <[email protected]>
Tue, 5 Jun 2012 11:44:31 +0000 (13:44 +0200)
src/MIME/Type/PlainDetect.php

index 9d55a2e90a647bc6013389fabf1b9d77cbdbd1b0..91e8d1f6ba82008968bcf84b23cf0297f936a18c 100644 (file)
@@ -11,7 +11,7 @@ class MIME_Type_PlainDetect
     public static function autoDetect($file)
     {
         $mt = new MIME_Type();
-        $mt->magicFile = __DIR__ . '/../../../data/programming.magic';
+        $mt->magicFile = static::getMagicFile();
         $mt->useMimeContentType = false;
         //fixme: finfo doesn't give the correct results
         // only fixed in PHP 5.4.4
@@ -28,6 +28,15 @@ class MIME_Type_PlainDetect
         $type = MIME_Type::autoDetect($file);
         return $type;
     }
+
+    public static function getMagicFile()
+    {
+        if ('@data_dir@' != '@' . 'data_dir@') {
+            //PEAR-installed version
+            return '@data_dir@/MIME_Type_PlainDetect/data/programming.magic';
+        }
+        return __DIR__ . '/../../../data/programming.magic';
+    }
 }
 
 ?>