‪TYPO3CMS  ‪main
PlatformInformation.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Doctrine\DBAL\Exception as DBALException;
21 use Doctrine\DBAL\Platforms\AbstractPlatform as DoctrineAbstractPlatform;
22 use Doctrine\DBAL\Platforms\MariaDBPlatform as DoctrineMariaDBPlatform;
23 use Doctrine\DBAL\Platforms\MySQLPlatform as DoctrineMySQLPlatform;
24 use Doctrine\DBAL\Platforms\PostgreSQLPlatform as DoctrinePostgreSQLPlatform;
25 use Doctrine\DBAL\Platforms\SQLitePlatform as DoctrineSQLitePlatform;
26 
33 {
34  protected static array ‪$identifierLimits = [
35  'mysql' => 63,
36  'postgresql' => 63,
37  'sqlite' => 1024, // arbitrary limit, SQLite is only limited by the total statement length
38  ];
39 
40  protected static array ‪$bindParameterLimits = [
41  'mysql' => 65535,
42  'postgresql' => 34464,
43  'sqlite' => 999,
44  ];
45 
49  protected static array ‪$charSetMap = [
50  'mysql' => 'utf8mb4',
51  'postgresql' => 'UTF8',
52  'sqlite' => 'utf8',
53  ];
54 
58  protected static array ‪$databaseCreateWithCharsetMap = [
59  'mysql' => 'CHARACTER SET %s',
60  'postgresql' => "ENCODING '%s'",
61  ];
62 
66  public static function ‪getCharset(DoctrineAbstractPlatform $platform): string
67  {
68  $platformName = static::getPlatformIdentifier($platform);
69  return static::$charSetMap[$platformName];
70  }
71 
75  public static function ‪getDatabaseCreateStatementWithCharset(DoctrineAbstractPlatform $platform, string $databaseName): string
76  {
77  try {
78  $createStatement = $platform->getCreateDatabaseSQL($databaseName);
79  } catch (DBALException $exception) {
80  // just silently ignore that error as the selected database does not support any creation of a database
81  return '';
82  }
83 
84  $platformName = static::getPlatformIdentifier($platform);
85  $charset = static::getCharset($platform);
86 
87  return $createStatement . ' ' . sprintf(static::$databaseCreateWithCharsetMap[$platformName], $charset);
88  }
89 
95  public static function ‪getMaxIdentifierLength(DoctrineAbstractPlatform $platform): int
96  {
97  $platformName = static::getPlatformIdentifier($platform);
98  return self::$identifierLimits[$platformName];
99  }
100 
106  public static function ‪getMaxBindParameters(DoctrineAbstractPlatform $platform): int
107  {
108  $platformName = static::getPlatformIdentifier($platform);
109  return self::$bindParameterLimits[$platformName];
110  }
111 
118  protected static function ‪getPlatformIdentifier(DoctrineAbstractPlatform $platform): string
119  {
120  // @todo: In doctrine/dbal 3 MariaDBPlatform extended from MySQLPlatform, since doctrine/dbal 4+ from
121  // AbstractMySQLPlatform. Consider to returning directly 'mariadb' here if consuming code is
122  // prepared for the change.
123  if ($platform instanceof DoctrineMariaDBPlatform) {
124  return 'mysql';
125  }
126  if ($platform instanceof DoctrineMySQLPlatform) {
127  return 'mysql';
128  }
129  if ($platform instanceof DoctrinePostgreSqlPlatform) {
130  return 'postgresql';
131  }
132  if ($platform instanceof DoctrineSQLitePlatform) {
133  return 'sqlite';
134  }
135  throw new \RuntimeException(
136  'Unsupported Databaseplatform "' . get_class($platform) . '" detected in PlatformInformation',
137  1500958070
138  );
139  }
140 }
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxBindParameters
‪static getMaxBindParameters(DoctrineAbstractPlatform $platform)
Definition: PlatformInformation.php:106
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getDatabaseCreateStatementWithCharset
‪static getDatabaseCreateStatementWithCharset(DoctrineAbstractPlatform $platform, string $databaseName)
Definition: PlatformInformation.php:75
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\$charSetMap
‪static array $charSetMap
Definition: PlatformInformation.php:49
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getCharset
‪static getCharset(DoctrineAbstractPlatform $platform)
Definition: PlatformInformation.php:66
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxIdentifierLength
‪static getMaxIdentifierLength(DoctrineAbstractPlatform $platform)
Definition: PlatformInformation.php:95
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\$identifierLimits
‪static array $identifierLimits
Definition: PlatformInformation.php:34
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\$bindParameterLimits
‪static array $bindParameterLimits
Definition: PlatformInformation.php:40
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\$databaseCreateWithCharsetMap
‪static array $databaseCreateWithCharsetMap
Definition: PlatformInformation.php:58
‪TYPO3\CMS\Core\Database\Platform
Definition: MariaDB1052Platform.php:18
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation
Definition: PlatformInformation.php:33
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getPlatformIdentifier
‪static getPlatformIdentifier(DoctrineAbstractPlatform $platform)
Definition: PlatformInformation.php:118