| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Endroid\QrCode\Encoding; |
| 6 |
|
| 7 |
final class Encoding implements EncodingInterface |
| 8 |
{ |
| 9 |
public function __construct( |
| 10 |
private readonly string $value |
| 11 |
) { |
| 12 |
if ('UTF-8' !== $value) { |
| 13 |
if (!function_exists('mb_list_encodings')) { |
| 14 |
throw new \Exception('Unable to validate encoding: make sure the mbstring extension is installed and enabled'); |
| 15 |
} |
| 16 |
|
| 17 |
if (!in_array($value, mb_list_encodings())) { |
| 18 |
throw new \Exception(sprintf('Invalid encoding "%s": choose one of '.implode(', ', mb_list_encodings()), $value)); |
| 19 |
} |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
public function __toString(): string |
| 24 |
{ |
| 25 |
return $this->value; |
| 26 |
} |
| 27 |
} |