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