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);
+ if ($returnError && $type instanceof \PEAR_Error) {
+ return $type;
+ }
+
return $this->findExtForType($type);
}
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);
}
}