'utf8mb4_bin', ]; private const MARIADB_DEFAULT_STAND_IN = 'utf8mb4_unicode_520_ci'; /** Prepares a CREATE TABLE for this server. */ public static function adapt( \wpdb $wpdb, string $sql ): string { // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- server metadata, nothing to cache $raw = (string) $wpdb->get_var( 'SELECT VERSION()' ); if ( ServerCapabilities::is_mariadb_version( $raw ) ) { $sql = self::for_mariadb( $sql, CollationMap::known( $wpdb ) ); } return CollationMap::adapt( $wpdb, $sql ); } /** * Removes MySQL 8 only versioned comments and maps its 0900 collations. * * @param array $known Collations the server reports, lowercase; empty when unreadable. */ public static function for_mariadb( string $sql, array $known ): string { // Versions 8NNNN are MySQL 8 only. Older ones, such as 40101, are portable and stay. $sql = (string) preg_replace( '/[ \t]*\/\*!8\d{4}\b.*?\*\//s', '', $sql ); return (string) preg_replace_callback( '/\butf8mb4_0900_[a-z0-9_]+/i', static function ( array $m ) use ( $known ): string { $name = strtolower( $m[0] ); if ( isset( $known[ $name ] ) ) { return $m[0]; } return self::MARIADB_STAND_INS[ $name ] ?? self::MARIADB_DEFAULT_STAND_IN; }, $sql ); } }