1 | <?php |
||
17 | class Transcoder implements TranscoderInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var TranscoderInterface |
||
21 | */ |
||
22 | protected $transcoder; |
||
23 | |||
24 | /** |
||
25 | * Is mbstring extension available? |
||
26 | * |
||
27 | * @var boolean |
||
28 | */ |
||
29 | protected $mbstringEnabled; |
||
30 | |||
31 | /** |
||
32 | * Is iconv extension available? |
||
33 | * |
||
34 | * @var boolean |
||
35 | */ |
||
36 | protected $iconvEnabled; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $bomList = [ |
||
42 | 'UTF-7' => [ |
||
43 | "\x2B\x2F\76\x38", |
||
44 | "\x2B\x2F\76\x39", |
||
45 | "\x2B\x2F\76\x2B", |
||
46 | "\x2B\x2F\76\x2F", |
||
47 | ], |
||
48 | 'UTF-8' => "\xEF\xBB\xBF", |
||
49 | 'UTF-16BE' => "\xFE\xFF", |
||
50 | 'UTF-16LE' => "\xFF\xFE", |
||
51 | 'UTF-32BE' => "\x00\x00\xFE\xFF", |
||
52 | 'UTF-32LE' => "\xFF\xFE\x00\x00", |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * @param string $defaultEncoding |
||
57 | * @param bool $forceMbString |
||
58 | */ |
||
59 | 63 | public function __construct($defaultEncoding = 'UTF-8', $forceMbString = false) |
|
72 | |||
73 | /** |
||
74 | * |
||
75 | * @param string $str |
||
76 | * @param string $fallback |
||
77 | * @return string |
||
78 | */ |
||
79 | 2 | public function detectEncoding($str, $fallback = 'UTF-8') |
|
115 | |||
116 | /** |
||
117 | * Transcode a string from one into another encoding |
||
118 | * |
||
119 | * @param string $string String |
||
120 | * @param string $from From encoding (optional) default = auto |
||
121 | * @param string $to To encoding (optional) default = UTF-8 |
||
122 | * @param string $iconvTranslit (optional) default = null Iconv translit option possible values : 'translit', 'ignore', null |
||
123 | * |
||
124 | * @return string |
||
125 | * |
||
126 | * @throws UnsupportedEncodingException |
||
127 | */ |
||
128 | 29 | public function transcode($string, $from = 'auto', $to = 'UTF-8', $iconvTranslit = null) |
|
148 | |||
149 | /** |
||
150 | * get BOM for given encoding |
||
151 | * |
||
152 | * @param string $encoding |
||
153 | * @return string BOM |
||
154 | */ |
||
155 | 5 | public function getBOM($encoding = 'UTF-8') |
|
159 | |||
160 | /** |
||
161 | * get Valid Windows CP encoding name for mb_string |
||
162 | * |
||
163 | * @param $encoding |
||
164 | * @return string |
||
165 | */ |
||
166 | 1 | protected function getWindowsCPEncoding($encoding) |
|
170 | } |
||
171 |