BitArray.php
1 week ago
BitMatrix.php
1 week ago
BitUtils.php
1 week ago
CharacterSetEci.php
1 week ago
EcBlock.php
1 week ago
EcBlocks.php
1 week ago
ErrorCorrectionLevel.php
1 week ago
FormatInformation.php
1 week ago
Mode.php
1 week ago
ReedSolomonCodec.php
1 week ago
Version.php
1 week ago
index.php
1 week ago
CharacterSetEci.php
161 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace WP2FA_Vendor\BaconQrCode\Common; |
| 5 | |
| 6 | use WP2FA_Vendor\BaconQrCode\Exception\InvalidArgumentException; |
| 7 | use WP2FA_Vendor\DASPRiD\Enum\AbstractEnum; |
| 8 | /** |
| 9 | * Encapsulates a Character Set ECI, according to "Extended Channel Interpretations" 5.3.1.1 of ISO 18004. |
| 10 | * |
| 11 | * @method static self CP437() |
| 12 | * @method static self ISO8859_1() |
| 13 | * @method static self ISO8859_2() |
| 14 | * @method static self ISO8859_3() |
| 15 | * @method static self ISO8859_4() |
| 16 | * @method static self ISO8859_5() |
| 17 | * @method static self ISO8859_6() |
| 18 | * @method static self ISO8859_7() |
| 19 | * @method static self ISO8859_8() |
| 20 | * @method static self ISO8859_9() |
| 21 | * @method static self ISO8859_10() |
| 22 | * @method static self ISO8859_11() |
| 23 | * @method static self ISO8859_12() |
| 24 | * @method static self ISO8859_13() |
| 25 | * @method static self ISO8859_14() |
| 26 | * @method static self ISO8859_15() |
| 27 | * @method static self ISO8859_16() |
| 28 | * @method static self SJIS() |
| 29 | * @method static self CP1250() |
| 30 | * @method static self CP1251() |
| 31 | * @method static self CP1252() |
| 32 | * @method static self CP1256() |
| 33 | * @method static self UNICODE_BIG_UNMARKED() |
| 34 | * @method static self UTF8() |
| 35 | * @method static self ASCII() |
| 36 | * @method static self BIG5() |
| 37 | * @method static self GB18030() |
| 38 | * @method static self EUC_KR() |
| 39 | */ |
| 40 | final class CharacterSetEci extends AbstractEnum |
| 41 | { |
| 42 | protected const CP437 = [[0, 2]]; |
| 43 | protected const ISO8859_1 = [[1, 3], 'ISO-8859-1']; |
| 44 | protected const ISO8859_2 = [[4], 'ISO-8859-2']; |
| 45 | protected const ISO8859_3 = [[5], 'ISO-8859-3']; |
| 46 | protected const ISO8859_4 = [[6], 'ISO-8859-4']; |
| 47 | protected const ISO8859_5 = [[7], 'ISO-8859-5']; |
| 48 | protected const ISO8859_6 = [[8], 'ISO-8859-6']; |
| 49 | protected const ISO8859_7 = [[9], 'ISO-8859-7']; |
| 50 | protected const ISO8859_8 = [[10], 'ISO-8859-8']; |
| 51 | protected const ISO8859_9 = [[11], 'ISO-8859-9']; |
| 52 | protected const ISO8859_10 = [[12], 'ISO-8859-10']; |
| 53 | protected const ISO8859_11 = [[13], 'ISO-8859-11']; |
| 54 | protected const ISO8859_12 = [[14], 'ISO-8859-12']; |
| 55 | protected const ISO8859_13 = [[15], 'ISO-8859-13']; |
| 56 | protected const ISO8859_14 = [[16], 'ISO-8859-14']; |
| 57 | protected const ISO8859_15 = [[17], 'ISO-8859-15']; |
| 58 | protected const ISO8859_16 = [[18], 'ISO-8859-16']; |
| 59 | protected const SJIS = [[20], 'Shift_JIS']; |
| 60 | protected const CP1250 = [[21], 'windows-1250']; |
| 61 | protected const CP1251 = [[22], 'windows-1251']; |
| 62 | protected const CP1252 = [[23], 'windows-1252']; |
| 63 | protected const CP1256 = [[24], 'windows-1256']; |
| 64 | protected const UNICODE_BIG_UNMARKED = [[25], 'UTF-16BE', 'UnicodeBig']; |
| 65 | protected const UTF8 = [[26], 'UTF-8']; |
| 66 | protected const ASCII = [[27, 170], 'US-ASCII']; |
| 67 | protected const BIG5 = [[28]]; |
| 68 | protected const GB18030 = [[29], 'GB2312', 'EUC_CN', 'GBK']; |
| 69 | protected const EUC_KR = [[30], 'EUC-KR']; |
| 70 | /** |
| 71 | * @var int[] |
| 72 | */ |
| 73 | private $values; |
| 74 | /** |
| 75 | * @var string[] |
| 76 | */ |
| 77 | private $otherEncodingNames; |
| 78 | /** |
| 79 | * @var array<int, self>|null |
| 80 | */ |
| 81 | private static $valueToEci; |
| 82 | /** |
| 83 | * @var array<string, self>|null |
| 84 | */ |
| 85 | private static $nameToEci; |
| 86 | /** |
| 87 | * @param int[] $values |
| 88 | */ |
| 89 | public function __construct(array $values, string ...$otherEncodingNames) |
| 90 | { |
| 91 | $this->values = $values; |
| 92 | $this->otherEncodingNames = $otherEncodingNames; |
| 93 | } |
| 94 | /** |
| 95 | * Returns the primary value. |
| 96 | */ |
| 97 | public function getValue() : int |
| 98 | { |
| 99 | return $this->values[0]; |
| 100 | } |
| 101 | /** |
| 102 | * Gets character set ECI by value. |
| 103 | * |
| 104 | * Returns the representing ECI of a given value, or null if it is legal but unsupported. |
| 105 | * |
| 106 | * @throws InvalidArgumentException if value is not between 0 and 900 |
| 107 | */ |
| 108 | public static function getCharacterSetEciByValue(int $value) : ?self |
| 109 | { |
| 110 | if ($value < 0 || $value >= 900) { |
| 111 | throw new InvalidArgumentException('Value must be between 0 and 900'); |
| 112 | } |
| 113 | $valueToEci = self::valueToEci(); |
| 114 | if (!\array_key_exists($value, $valueToEci)) { |
| 115 | return null; |
| 116 | } |
| 117 | return $valueToEci[$value]; |
| 118 | } |
| 119 | /** |
| 120 | * Returns character set ECI by name. |
| 121 | * |
| 122 | * Returns the representing ECI of a given name, or null if it is legal but unsupported |
| 123 | */ |
| 124 | public static function getCharacterSetEciByName(string $name) : ?self |
| 125 | { |
| 126 | $nameToEci = self::nameToEci(); |
| 127 | $name = \strtolower($name); |
| 128 | if (!\array_key_exists($name, $nameToEci)) { |
| 129 | return null; |
| 130 | } |
| 131 | return $nameToEci[$name]; |
| 132 | } |
| 133 | private static function valueToEci() : array |
| 134 | { |
| 135 | if (null !== self::$valueToEci) { |
| 136 | return self::$valueToEci; |
| 137 | } |
| 138 | self::$valueToEci = []; |
| 139 | foreach (self::values() as $eci) { |
| 140 | foreach ($eci->values as $value) { |
| 141 | self::$valueToEci[$value] = $eci; |
| 142 | } |
| 143 | } |
| 144 | return self::$valueToEci; |
| 145 | } |
| 146 | private static function nameToEci() : array |
| 147 | { |
| 148 | if (null !== self::$nameToEci) { |
| 149 | return self::$nameToEci; |
| 150 | } |
| 151 | self::$nameToEci = []; |
| 152 | foreach (self::values() as $eci) { |
| 153 | self::$nameToEci[\strtolower($eci->name())] = $eci; |
| 154 | foreach ($eci->otherEncodingNames as $name) { |
| 155 | self::$nameToEci[\strtolower($name)] = $eci; |
| 156 | } |
| 157 | } |
| 158 | return self::$nameToEci; |
| 159 | } |
| 160 | } |
| 161 |