show reason for mime type detection failure in setup check
authorChristian Weiske <cweiske@cweiske.de>
Wed, 9 Jul 2014 16:21:08 +0000 (18:21 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 9 Jul 2014 16:21:08 +0000 (18:21 +0200)
src/phorkie/Repository/Post.php
src/phorkie/SetupCheck.php

index 5a450b1..09cb977 100644 (file)
@@ -232,13 +232,17 @@ class Repository_Post
         return $prefix . $num;
     }
 
         return $prefix . $num;
     }
 
-    public function getType($content)
+    public function getType($content, $returnError = false)
     {
         $tmp = tempnam(sys_get_temp_dir(), 'phorkie-autodetect-');
         file_put_contents($tmp, $content);
         $type = Tool_MIME_Type_PlainDetect::autoDetect($tmp);
         unlink($tmp);
 
     {
         $tmp = tempnam(sys_get_temp_dir(), 'phorkie-autodetect-');
         file_put_contents($tmp, $content);
         $type = Tool_MIME_Type_PlainDetect::autoDetect($tmp);
         unlink($tmp);
 
+        if ($returnError && $type instanceof \PEAR_Error) {
+            return $type;
+        }
+
         return $this->findExtForType($type);
     }
 
         return $this->findExtForType($type);
     }
 
index c4d365c..e06f28c 100644 (file)
@@ -133,8 +133,13 @@ class SetupCheck
     public function checkMimeTypeDetection()
     {
         $rp = new Repository_Post();
     public function checkMimeTypeDetection()
     {
         $rp = new Repository_Post();
-        if ($rp->getType('<?php echo "foo"; ?>') != 'php') {
-            $this->fail('MIME type detection fails');
+        $type = $rp->getType('<?php echo "foo"; ?>', true);
+        if ($type != 'php') {
+            $msg = 'MIME type detection fails';
+            if ($type instanceof \PEAR_Error) {
+                $msg .= '. Error: ' . $type->getMessage();
+            }
+            $this->fail($msg);
         }
     }
 
         }
     }