diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Platforms/MySQL/CharsetMetadataProvider')
2 files changed, 66 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Platforms/MySQL/CharsetMetadataProvider/CachingCharsetMetadataProvider.php b/vendor/doctrine/dbal/src/Platforms/MySQL/CharsetMetadataProvider/CachingCharsetMetadataProvider.php new file mode 100644 index 0000000..dadc841 --- /dev/null +++ b/vendor/doctrine/dbal/src/Platforms/MySQL/CharsetMetadataProvider/CachingCharsetMetadataProvider.php | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Platforms\MySQL\CharsetMetadataProvider; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Platforms\MySQL\CharsetMetadataProvider; | ||
| 8 | |||
| 9 | use function array_key_exists; | ||
| 10 | |||
| 11 | /** @internal */ | ||
| 12 | final class CachingCharsetMetadataProvider implements CharsetMetadataProvider | ||
| 13 | { | ||
| 14 | /** @var array<string,?string> */ | ||
| 15 | private array $cache = []; | ||
| 16 | |||
| 17 | public function __construct(private readonly CharsetMetadataProvider $charsetMetadataProvider) | ||
| 18 | { | ||
| 19 | } | ||
| 20 | |||
| 21 | public function getDefaultCharsetCollation(string $charset): ?string | ||
| 22 | { | ||
| 23 | if (array_key_exists($charset, $this->cache)) { | ||
| 24 | return $this->cache[$charset]; | ||
| 25 | } | ||
| 26 | |||
| 27 | return $this->cache[$charset] = $this->charsetMetadataProvider->getDefaultCharsetCollation($charset); | ||
| 28 | } | ||
| 29 | } | ||
diff --git a/vendor/doctrine/dbal/src/Platforms/MySQL/CharsetMetadataProvider/ConnectionCharsetMetadataProvider.php b/vendor/doctrine/dbal/src/Platforms/MySQL/CharsetMetadataProvider/ConnectionCharsetMetadataProvider.php new file mode 100644 index 0000000..65b63df --- /dev/null +++ b/vendor/doctrine/dbal/src/Platforms/MySQL/CharsetMetadataProvider/ConnectionCharsetMetadataProvider.php | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Platforms\MySQL\CharsetMetadataProvider; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Connection; | ||
| 8 | use Doctrine\DBAL\Exception; | ||
| 9 | use Doctrine\DBAL\Platforms\MySQL\CharsetMetadataProvider; | ||
| 10 | |||
| 11 | /** @internal */ | ||
| 12 | final class ConnectionCharsetMetadataProvider implements CharsetMetadataProvider | ||
| 13 | { | ||
| 14 | public function __construct(private readonly Connection $connection) | ||
| 15 | { | ||
| 16 | } | ||
| 17 | |||
| 18 | /** @throws Exception */ | ||
| 19 | public function getDefaultCharsetCollation(string $charset): ?string | ||
| 20 | { | ||
| 21 | $collation = $this->connection->fetchOne( | ||
| 22 | <<<'SQL' | ||
| 23 | SELECT DEFAULT_COLLATE_NAME | ||
| 24 | FROM information_schema.CHARACTER_SETS | ||
| 25 | WHERE CHARACTER_SET_NAME = ?; | ||
| 26 | SQL | ||
| 27 | , | ||
| 28 | [$charset], | ||
| 29 | ); | ||
| 30 | |||
| 31 | if ($collation !== false) { | ||
| 32 | return $collation; | ||
| 33 | } | ||
| 34 | |||
| 35 | return null; | ||
| 36 | } | ||
| 37 | } | ||
