Просмотр файла vendor/nelexa/zip/src/Constants/DosCodePage.php

Размер файла: 1.88Kb
  1. <?php
  2.  
  3. /** @noinspection PhpComposerExtensionStubsInspection */
  4.  
  5. namespace PhpZip\Constants;
  6.  
  7. /**
  8. * Class DosCodePage.
  9. */
  10. final class DosCodePage
  11. {
  12. const CP_LATIN_US = 'cp437';
  13.  
  14. const CP_GREEK = 'cp737';
  15.  
  16. const CP_BALT_RIM = 'cp775';
  17.  
  18. const CP_LATIN1 = 'cp850';
  19.  
  20. const CP_LATIN2 = 'cp852';
  21.  
  22. const CP_CYRILLIC = 'cp855';
  23.  
  24. const CP_TURKISH = 'cp857';
  25.  
  26. const CP_PORTUGUESE = 'cp860';
  27.  
  28. const CP_ICELANDIC = 'cp861';
  29.  
  30. const CP_HEBREW = 'cp862';
  31.  
  32. const CP_CANADA = 'cp863';
  33.  
  34. const CP_ARABIC = 'cp864';
  35.  
  36. const CP_NORDIC = 'cp865';
  37.  
  38. const CP_CYRILLIC_RUSSIAN = 'cp866';
  39.  
  40. const CP_GREEK2 = 'cp869';
  41.  
  42. const CP_THAI = 'cp874';
  43.  
  44. /** @var string[] */
  45. private static $CP_CHARSETS = [
  46. self::CP_LATIN_US,
  47. self::CP_GREEK,
  48. self::CP_BALT_RIM,
  49. self::CP_LATIN1,
  50. self::CP_LATIN2,
  51. self::CP_CYRILLIC,
  52. self::CP_TURKISH,
  53. self::CP_PORTUGUESE,
  54. self::CP_ICELANDIC,
  55. self::CP_HEBREW,
  56. self::CP_CANADA,
  57. self::CP_ARABIC,
  58. self::CP_NORDIC,
  59. self::CP_CYRILLIC_RUSSIAN,
  60. self::CP_GREEK2,
  61. self::CP_THAI,
  62. ];
  63.  
  64. /**
  65. * @param string $str
  66. * @param string $sourceEncoding
  67. *
  68. * @return string
  69. */
  70. public static function toUTF8($str, $sourceEncoding)
  71. {
  72. $s = iconv($sourceEncoding, 'UTF-8', $str);
  73.  
  74. if ($s === false) {
  75. return $str;
  76. }
  77.  
  78. return $s;
  79. }
  80.  
  81. /**
  82. * @param string $str
  83. * @param string $destEncoding
  84. *
  85. * @return string
  86. */
  87. public static function fromUTF8($str, $destEncoding)
  88. {
  89. $s = iconv('UTF-8', $destEncoding, $str);
  90.  
  91. if ($s === false) {
  92. return $str;
  93. }
  94.  
  95. return $s;
  96. }
  97.  
  98. /**
  99. * @return string[]
  100. */
  101. public static function getCodePages()
  102. {
  103. return self::$CP_CHARSETS;
  104. }
  105. }