‪TYPO3CMS  10.4
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\DBALException;
21 use Doctrine\DBAL\Platforms\AbstractPlatform;
22 use Doctrine\DBAL\Platforms\MySqlPlatform;
23 use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
24 use Doctrine\DBAL\Platforms\SqlitePlatform;
25 use Doctrine\DBAL\Platforms\SQLServerPlatform;
26 
33 {
37  protected static ‪$identifierLimits = [
38  'mysql' => 63,
39  'postgresql' => 63,
40  'sqlserver' => 128,
41  'sqlite' => 1024, // arbitrary limit, SQLite is only limited by the total statement length
42  ];
43 
47  protected static ‪$bindParameterLimits = [
48  'mysql' => 65535,
49  'postgresql' => 34464,
50  'sqlserver' => 2100,
51  'sqlite' => 999,
52  ];
53 
57  protected static ‪$charSetMap = [
58  'mysql' => 'utf8mb4',
59  'postgresql' => 'UTF8',
60  'sqlserver' => 'UTF-8',
61  'sqlite' => 'utf8',
62  ];
63 
67  protected static ‪$databaseCreateWithCharsetMap = [
68  'mysql' => 'CHARACTER SET %s',
69  'postgresql' => "ENCODING '%s'",
70  'sqlserver' => '',
71  ];
72 
79  public static function ‪getCharset(AbstractPlatform $platform): string
80  {
81  $platformName = static::getPlatformIdentifier($platform);
82 
83  return static::$charSetMap[$platformName];
84  }
85 
93  public static function ‪getDatabaseCreateStatementWithCharset(AbstractPlatform $platform, string $databaseName): string
94  {
95  try {
96  $createStatement = $platform->getCreateDatabaseSQL($databaseName);
97  } catch (DBALException $exception) {
98  // just silently ignore that error as the selected database does not support any creation of a database
99  return '';
100  }
101 
102  $platformName = static::getPlatformIdentifier($platform);
103  $charset = static::getCharset($platform);
104 
105  return $createStatement . ' ' . sprintf(static::$databaseCreateWithCharsetMap[$platformName], $charset);
106  }
107 
115  public static function ‪getMaxIdentifierLength(AbstractPlatform $platform): int
116  {
117  $platformName = static::getPlatformIdentifier($platform);
118 
119  return self::$identifierLimits[$platformName];
120  }
121 
129  public static function ‪getMaxBindParameters(AbstractPlatform $platform): int
130  {
131  $platformName = static::getPlatformIdentifier($platform);
132 
133  return self::$bindParameterLimits[$platformName];
134  }
135 
144  protected static function ‪getPlatformIdentifier(AbstractPlatform $platform): string
145  {
146  if ($platform instanceof MySqlPlatform) {
147  return 'mysql';
148  }
149  if ($platform instanceof PostgreSqlPlatform) {
150  return 'postgresql';
151  }
152  if ($platform instanceof SQLServerPlatform) {
153  return 'sqlserver';
154  }
155  if ($platform instanceof SqlitePlatform) {
156  return 'sqlite';
157  }
158  throw new \RuntimeException(
159  'Unsupported Databaseplatform "' . get_class($platform) . '" detected in PlatformInformation',
160  1500958070
161  );
162  }
163 }
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\$charSetMap
‪static string[] $charSetMap
Definition: PlatformInformation.php:54
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\$databaseCreateWithCharsetMap
‪static string[] $databaseCreateWithCharsetMap
Definition: PlatformInformation.php:63
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getCharset
‪static string getCharset(AbstractPlatform $platform)
Definition: PlatformInformation.php:75
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getDatabaseCreateStatementWithCharset
‪static string getDatabaseCreateStatementWithCharset(AbstractPlatform $platform, string $databaseName)
Definition: PlatformInformation.php:89
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getPlatformIdentifier
‪static string getPlatformIdentifier(AbstractPlatform $platform)
Definition: PlatformInformation.php:140
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxBindParameters
‪static int getMaxBindParameters(AbstractPlatform $platform)
Definition: PlatformInformation.php:125
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\$identifierLimits
‪static array $identifierLimits
Definition: PlatformInformation.php:36
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\$bindParameterLimits
‪static array $bindParameterLimits
Definition: PlatformInformation.php:45
‪TYPO3\CMS\Core\Database\Platform
Definition: PlatformInformation.php:18
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation
Definition: PlatformInformation.php:33
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxIdentifierLength
‪static int getMaxIdentifierLength(AbstractPlatform $platform)
Definition: PlatformInformation.php:111