| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <[email protected]> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
use Symfony\Polyfill\Iconv as p; |
| 13 |
|
| 14 |
if (!defined('ICONV_IMPL')) { |
| 15 |
define('ICONV_IMPL', 'Symfony'); |
| 16 |
} |
| 17 |
if (!defined('ICONV_VERSION')) { |
| 18 |
define('ICONV_VERSION', '1.0'); |
| 19 |
} |
| 20 |
if (!defined('ICONV_MIME_DECODE_STRICT')) { |
| 21 |
define('ICONV_MIME_DECODE_STRICT', 1); |
| 22 |
} |
| 23 |
if (!defined('ICONV_MIME_DECODE_CONTINUE_ON_ERROR')) { |
| 24 |
define('ICONV_MIME_DECODE_CONTINUE_ON_ERROR', 2); |
| 25 |
} |
| 26 |
|
| 27 |
if (!function_exists('iconv')) { |
| 28 |
function iconv(?string $from_encoding, ?string $to_encoding, ?string $string): string|false { return p\Iconv::iconv((string) $from_encoding, (string) $to_encoding, (string) $string); } |
| 29 |
} |
| 30 |
if (!function_exists('iconv_get_encoding')) { |
| 31 |
function iconv_get_encoding(?string $type = 'all'): array|string|false { return p\Iconv::iconv_get_encoding((string) $type); } |
| 32 |
} |
| 33 |
if (!function_exists('iconv_set_encoding')) { |
| 34 |
function iconv_set_encoding(?string $type, ?string $encoding): bool { return p\Iconv::iconv_set_encoding((string) $type, (string) $encoding); } |
| 35 |
} |
| 36 |
if (!function_exists('iconv_mime_encode')) { |
| 37 |
function iconv_mime_encode(?string $field_name, ?string $field_value, ?array $options = []): string|false { return p\Iconv::iconv_mime_encode((string) $field_name, (string) $field_value, (array) $options); } |
| 38 |
} |
| 39 |
if (!function_exists('iconv_mime_decode_headers')) { |
| 40 |
function iconv_mime_decode_headers(?string $headers, ?int $mode = 0, ?string $encoding = null): array|false { return p\Iconv::iconv_mime_decode_headers((string) $headers, (int) $mode, $encoding); } |
| 41 |
} |
| 42 |
|
| 43 |
if (extension_loaded('mbstring')) { |
| 44 |
if (!function_exists('iconv_strlen')) { |
| 45 |
function iconv_strlen(?string $string, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strlen((string) $string, $encoding); } |
| 46 |
} |
| 47 |
if (!function_exists('iconv_strpos')) { |
| 48 |
function iconv_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
| 49 |
} |
| 50 |
if (!function_exists('iconv_strrpos')) { |
| 51 |
function iconv_strrpos(?string $haystack, ?string $needle, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strrpos((string) $haystack, (string) $needle, 0, $encoding); } |
| 52 |
} |
| 53 |
if (!function_exists('iconv_substr')) { |
| 54 |
function iconv_substr(?string $string, ?int $offset, ?int $length = null, ?string $encoding = null): string|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_substr((string) $string, (int) $offset, $length, $encoding); } |
| 55 |
} |
| 56 |
if (!function_exists('iconv_mime_decode')) { |
| 57 |
function iconv_mime_decode($string, $mode = 0, $encoding = null) { $currentMbEncoding = mb_internal_encoding(); null === $encoding && $encoding = p\Iconv::$internalEncoding; mb_internal_encoding($encoding); $decoded = mb_decode_mimeheader($string); mb_internal_encoding($currentMbEncoding); return $decoded; } |
| 58 |
} |
| 59 |
} else { |
| 60 |
if (!function_exists('iconv_strlen')) { |
| 61 |
if (extension_loaded('xml')) { |
| 62 |
function iconv_strlen(?string $string, ?string $encoding = null): int|false { return p\Iconv::strlen1((string) $string, $encoding); } |
| 63 |
} else { |
| 64 |
function iconv_strlen(?string $string, ?string $encoding = null): int|false { return p\Iconv::strlen2((string) $string, $encoding); } |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
if (!function_exists('iconv_strpos')) { |
| 69 |
function iconv_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Iconv::iconv_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
| 70 |
} |
| 71 |
if (!function_exists('iconv_strrpos')) { |
| 72 |
function iconv_strrpos(?string $haystack, ?string $needle, ?string $encoding = null): int|false { return p\Iconv::iconv_strrpos((string) $haystack, (string) $needle, $encoding); } |
| 73 |
} |
| 74 |
if (!function_exists('iconv_substr')) { |
| 75 |
function iconv_substr(?string $string, ?int $offset, ?int $length = null, ?string $encoding = null): string|false { return p\Iconv::iconv_substr((string) $string, (string) $offset, $length, $encoding); } |
| 76 |
} |
| 77 |
if (!function_exists('iconv_mime_decode')) { |
| 78 |
function iconv_mime_decode(?string $string, ?int $mode = 0, ?string $encoding = null): string|false { return p\Iconv::iconv_mime_decode((string) $string, (int) $mode, $encoding); } |
| 79 |
} |
| 80 |
} |
| 81 |
|