diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Platforms/MySQL')
8 files changed, 270 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Platforms/MySQL/CharsetMetadataProvider.php b/vendor/doctrine/dbal/src/Platforms/MySQL/CharsetMetadataProvider.php new file mode 100644 index 0000000..665543e --- /dev/null +++ b/vendor/doctrine/dbal/src/Platforms/MySQL/CharsetMetadataProvider.php | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Platforms\MySQL; | ||
| 6 | |||
| 7 | /** @internal */ | ||
| 8 | interface CharsetMetadataProvider | ||
| 9 | { | ||
| 10 | public function getDefaultCharsetCollation(string $charset): ?string; | ||
| 11 | } | ||
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 | } | ||
diff --git a/vendor/doctrine/dbal/src/Platforms/MySQL/CollationMetadataProvider.php b/vendor/doctrine/dbal/src/Platforms/MySQL/CollationMetadataProvider.php new file mode 100644 index 0000000..d52ca74 --- /dev/null +++ b/vendor/doctrine/dbal/src/Platforms/MySQL/CollationMetadataProvider.php | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Platforms\MySQL; | ||
| 6 | |||
| 7 | /** @internal */ | ||
| 8 | interface CollationMetadataProvider | ||
| 9 | { | ||
| 10 | public function getCollationCharset(string $collation): ?string; | ||
| 11 | } | ||
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 | } | ||
diff --git a/vendor/doctrine/dbal/src/Platforms/MySQL/Comparator.php b/vendor/doctrine/dbal/src/Platforms/MySQL/Comparator.php new file mode 100644 index 0000000..ebe025d --- /dev/null +++ b/vendor/doctrine/dbal/src/Platforms/MySQL/Comparator.php | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Platforms\MySQL; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; | ||
| 8 | use Doctrine\DBAL\Schema\Comparator as BaseComparator; | ||
| 9 | use Doctrine\DBAL\Schema\Table; | ||
| 10 | use Doctrine\DBAL\Schema\TableDiff; | ||
| 11 | |||
| 12 | use function array_diff_assoc; | ||
| 13 | |||
| 14 | /** | ||
| 15 | * Compares schemas in the context of MySQL platform. | ||
| 16 | * | ||
| 17 | * In MySQL, unless specified explicitly, the column's character set and collation are inherited from its containing | ||
| 18 | * table. So during comparison, an omitted value and the value that matches the default value of table in the | ||
| 19 | * desired schema must be considered equal. | ||
| 20 | */ | ||
| 21 | class Comparator extends BaseComparator | ||
| 22 | { | ||
| 23 | /** @internal The comparator can be only instantiated by a schema manager. */ | ||
| 24 | public function __construct( | ||
| 25 | AbstractMySQLPlatform $platform, | ||
| 26 | private readonly CharsetMetadataProvider $charsetMetadataProvider, | ||
| 27 | private readonly CollationMetadataProvider $collationMetadataProvider, | ||
| 28 | private readonly DefaultTableOptions $defaultTableOptions, | ||
| 29 | ) { | ||
| 30 | parent::__construct($platform); | ||
| 31 | } | ||
| 32 | |||
| 33 | public function compareTables(Table $oldTable, Table $newTable): TableDiff | ||
| 34 | { | ||
| 35 | return parent::compareTables( | ||
| 36 | $this->normalizeTable($oldTable), | ||
| 37 | $this->normalizeTable($newTable), | ||
| 38 | ); | ||
| 39 | } | ||
| 40 | |||
| 41 | private function normalizeTable(Table $table): Table | ||
| 42 | { | ||
| 43 | $charset = $table->getOption('charset'); | ||
| 44 | $collation = $table->getOption('collation'); | ||
| 45 | |||
| 46 | if ($charset === null && $collation !== null) { | ||
| 47 | $charset = $this->collationMetadataProvider->getCollationCharset($collation); | ||
| 48 | } elseif ($charset !== null && $collation === null) { | ||
| 49 | $collation = $this->charsetMetadataProvider->getDefaultCharsetCollation($charset); | ||
| 50 | } elseif ($charset === null && $collation === null) { | ||
| 51 | $charset = $this->defaultTableOptions->getCharset(); | ||
| 52 | $collation = $this->defaultTableOptions->getCollation(); | ||
| 53 | } | ||
| 54 | |||
| 55 | $tableOptions = [ | ||
| 56 | 'charset' => $charset, | ||
| 57 | 'collation' => $collation, | ||
| 58 | ]; | ||
| 59 | |||
| 60 | $table = clone $table; | ||
| 61 | |||
| 62 | foreach ($table->getColumns() as $column) { | ||
| 63 | $originalOptions = $column->getPlatformOptions(); | ||
| 64 | $normalizedOptions = $this->normalizeOptions($originalOptions); | ||
| 65 | |||
| 66 | $overrideOptions = array_diff_assoc($normalizedOptions, $tableOptions); | ||
| 67 | |||
| 68 | if ($overrideOptions === $originalOptions) { | ||
| 69 | continue; | ||
| 70 | } | ||
| 71 | |||
| 72 | $column->setPlatformOptions($overrideOptions); | ||
| 73 | } | ||
| 74 | |||
| 75 | return $table; | ||
| 76 | } | ||
| 77 | |||
| 78 | /** | ||
| 79 | * @param array<string,string> $options | ||
| 80 | * | ||
| 81 | * @return array<string,string|null> | ||
| 82 | */ | ||
| 83 | private function normalizeOptions(array $options): array | ||
| 84 | { | ||
| 85 | if (isset($options['charset']) && ! isset($options['collation'])) { | ||
| 86 | $options['collation'] = $this->charsetMetadataProvider->getDefaultCharsetCollation($options['charset']); | ||
| 87 | } elseif (isset($options['collation']) && ! isset($options['charset'])) { | ||
| 88 | $options['charset'] = $this->collationMetadataProvider->getCollationCharset($options['collation']); | ||
| 89 | } | ||
| 90 | |||
| 91 | return $options; | ||
| 92 | } | ||
| 93 | } | ||
diff --git a/vendor/doctrine/dbal/src/Platforms/MySQL/DefaultTableOptions.php b/vendor/doctrine/dbal/src/Platforms/MySQL/DefaultTableOptions.php new file mode 100644 index 0000000..ede3ba2 --- /dev/null +++ b/vendor/doctrine/dbal/src/Platforms/MySQL/DefaultTableOptions.php | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Platforms\MySQL; | ||
| 6 | |||
| 7 | /** @internal */ | ||
| 8 | final class DefaultTableOptions | ||
| 9 | { | ||
| 10 | public function __construct(private readonly string $charset, private readonly string $collation) | ||
| 11 | { | ||
| 12 | } | ||
| 13 | |||
| 14 | public function getCharset(): string | ||
| 15 | { | ||
| 16 | return $this->charset; | ||
| 17 | } | ||
| 18 | |||
| 19 | public function getCollation(): string | ||
| 20 | { | ||
| 21 | return $this->collation; | ||
| 22 | } | ||
| 23 | } | ||
