Permalink
Browse files

added extra checks in case a file is detected as being 'binary'. In t…

…hat case it will retry with one of the alternative transliteration methods or error in the end when none suffices
  • Loading branch information...
1 parent 9d1b912 commit bfb2d7900e3a4b60fef7917a697ae265eedbddfb @mvriel mvriel committed Aug 5, 2011
Showing with 18 additions and 3 deletions.
  1. +18 −3 src/DocBlox/Reflection/File.php
@@ -173,24 +173,39 @@ protected function convertToUtf8($filename, $contents)
$encoding = $encoding[1];
}
- } elseif (function_exists('mb_detect_encoding')) {
+ }
+
+ // if the encoding is detected as binary we try again
+ if ((($encoding === null) || (strtolower($encoding) == 'binary'))
+ && function_exists('mb_detect_encoding')
+ ) {
// OR with mbstring
$encoding = mb_detect_encoding($contents);
- } elseif (function_exists('iconv')) {
+ }
+
+ // if the encoding is detected as binary we try again
+ if ((($encoding === null) || (strtolower($encoding) == 'binary'))
+ && function_exists('iconv')) {
// OR using iconv (performance hit)
$this->log(
'Neither the finfo nor the mbstring extensions are active; '
. 'special character handling may not give the best results',
Zend_Log::WARN
);
$encoding = $this->_detectEncodingFallback($contents);
- } else {
+ }
+
+ // if the encoding has failed or is detected as binary we give up
+ if (($encoding === null) || (strtolower($encoding) == 'binary')) {
// or not..
$this->log(
'Unable to handle character encoding; finfo, mbstring and '
. 'iconv extensions are not enabled',
Zend_Log::CRIT
);
+
+ // nothing will be returns to prevent handling
+ return '';
}
// if the encoding is unknown-8bit or x-user-defined we assume it might

0 comments on commit bfb2d79

Please sign in to comment.