@@ -38,24 +38,18 @@ public function getSource() {
38
38
return $ this ->src ;
39
39
}
40
40
41
- $ code = file_get_contents ($ this ->getPathname ());
42
-
43
- $ info = new \finfo ();
44
- $ encoding = $ info ->file ( (string )$ this , FILEINFO_MIME_ENCODING );
45
- if (strtolower ($ encoding ) != 'utf-8 ' && $ code != '' ) {
46
- try {
47
- $ code = iconv ($ encoding , 'UTF-8//TRANSLIT ' , $ code );
48
- } catch (\ErrorException $ e ) {
49
- throw new SourceFileException ('Encoding error - conversion to UTF-8 failed ' , SourceFileException::BadEncoding, $ e );
50
- }
41
+ $ source = file_get_contents ($ this ->getPathname ());
42
+ if ($ source == '' ) {
43
+ $ this ->src = '' ;
44
+ return '' ;
51
45
}
52
46
53
- // This is a workaround to filter out leftover invalid UTF-8 byte sets
54
- // even if the source looks like it's UTF-8 already
55
- mb_substitute_character ( ' none ' );
56
- $ cleanCode = mb_convert_encoding ( $ code , 'UTF-8 ' , ' UTF-8 ' );
57
- if ( $ cleanCode != $ code ) {
58
- throw new SourceFileException ('Encoding error - invalid UTF-8 bytes found ' , SourceFileException::InvalidDataBytes );
47
+ $ info = new \ finfo ();
48
+ $ encoding = $ info -> file (( string ) $ this , FILEINFO_MIME_ENCODING );
49
+ try {
50
+ $ source = iconv ( $ encoding , 'UTF-8//TRANSLIT ' , $ source );
51
+ } catch ( \ ErrorException $ e ) {
52
+ throw new SourceFileException ('Encoding error - conversion to UTF-8 failed ' , SourceFileException::BadEncoding, $ e );
59
53
}
60
54
61
55
// Replace xml relevant control characters by surrogates
@@ -65,7 +59,7 @@ function(array $matches) {
65
59
$ unicodeChar = '\u ' . (2400 + ord ($ matches [0 ]));
66
60
return json_decode ('" ' .$ unicodeChar .'" ' );
67
61
},
68
- $ cleanCode
62
+ $ source
69
63
);
70
64
71
65
return $ this ->src ;
0 commit comments