‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Database\ConnectionPool Class Reference

Public Member Functions

 getConnectionForTable (string $tableName)
 
 getConnectionByName (string $connectionName)
 
array getConnectionMiddlewareConfigurationArrayForLowLevelConfiguration ()
 
 getQueryBuilderForTable (string $tableName)
 
 getConnectionNames ()
 
 registerDoctrineTypes ()
 
 resetConnections ()
 

Public Attributes

const DEFAULT_CONNECTION_NAME = 'Default'
 
 $driverMiddlewares [$identifier]['type'] = 'global'
 
foreach($connectionParams['driverMiddlewares'] ??[] as $identifier=> $middleware) $driverMiddlewares
 

Protected Member Functions

 getConnectionParams (string $connectionName)
 
 getDriverMiddlewares (string $connectionName, array $connectionParams)
 
array< non-empty-string, getOrderedConnectionDriverMiddlewareConfiguration(string $connectionName, array $connectionParams):array { $driverMiddlewareService=GeneralUtility::makeInstance(DriverMiddlewareService::class);$driverMiddlewares=[];foreach( $GLOBALS[ 'TYPO3_CONF_VARS'][ 'DB'][ 'globalDriverMiddlewares'] ??[] as $identifier=> $middleware) { $identifier=(string) $identifier;$driverMiddlewares[ $identifier]=$driverMiddlewareService-> ensureCompleteMiddlewareConfiguration ( $driverMiddlewareService->normalizeMiddlewareConfiguration($identifier, $middleware))
 
 getDatabaseConnection (string $connectionName, array $connectionParams)
 

Protected Attributes

array $customDoctrineTypes
 
array $overrideDoctrineTypes
 

Static Protected Attributes

static Connection[] $connections = array( )
 

Detailed Description

Manager that handles opening/retrieving database connections.

It's a facade to the actual Doctrine DBAL DriverManager that implements TYPO3 specific functionality like mapping individual tables to different database connections.

getConnectionForTable() is the only supported way to get a connection that honors the table mapping configuration.

Definition at line 45 of file ConnectionPool.php.

Member Function Documentation

◆ ensureCompleteMiddlewareConfiguration()

array<non-empty-string, getOrderedConnectionDriverMiddlewareConfiguration(string $connectionName, array $connectionParams): array { $driverMiddlewareService = GeneralUtility::makeInstance(DriverMiddlewareService::class); $driverMiddlewares = []; foreach ($GLOBALS['TYPO3_CONF_VARS']['DB']['globalDriverMiddlewares'] ?? [] as $identifier => $middleware) { $identifier = (string)$identifier; $driverMiddlewares[$identifier] = $driverMiddlewareService-> TYPO3\CMS\Core\Database\ConnectionPool::ensureCompleteMiddlewareConfiguration ( $driverMiddlewareService->  normalizeMiddlewareConfiguration $identifier, $middleware)
protected
Parameters
array$connectionParams
Returns
‪array<non-empty-string, array{target: class-string, disabled: bool, after: string[], before: string[], type: string}>

◆ getConnectionByName()

TYPO3\CMS\Core\Database\ConnectionPool::getConnectionByName ( string  $connectionName)

Creates a connection object based on the specified identifier.

This method should only be used in edge cases. Use getConnectionForTable() so that the tablename<>databaseConnection mapping will be taken into account.

Parameters
string$connectionName
Exceptions

Definition at line 108 of file ConnectionPool.php.

References TYPO3\CMS\Core\Database\ConnectionPool\getConnectionParams(), and TYPO3\CMS\Core\Database\ConnectionPool\getDatabaseConnection().

Referenced by TYPO3\CMS\Core\Database\ConnectionPool\getConnectionForTable().

◆ getConnectionForTable()

TYPO3\CMS\Core\Database\ConnectionPool::getConnectionForTable ( string  $tableName)

Creates a connection object based on the specified table name.

This is the official entry point to get a database connection to ensure that the mapping of table names to database connections is honored.

Parameters
string$tableName

Definition at line 82 of file ConnectionPool.php.

References $GLOBALS, TYPO3\CMS\Core\Database\ConnectionPool\DEFAULT_CONNECTION_NAME, and TYPO3\CMS\Core\Database\ConnectionPool\getConnectionByName().

Referenced by TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserGroupRepository\__construct(), TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\__construct(), TYPO3\CMS\Impexp\Domain\Repository\PresetRepository\__construct(), and TYPO3\CMS\Core\Database\ConnectionPool\getQueryBuilderForTable().

◆ getConnectionMiddlewareConfigurationArrayForLowLevelConfiguration()

array TYPO3\CMS\Core\Database\ConnectionPool::getConnectionMiddlewareConfigurationArrayForLowLevelConfiguration ( )

only for ext:lowlevel usage to retrieve configuration overview. *

Returns
‪array

Definition at line 198 of file ConnectionPool.php.

References $GLOBALS, and TYPO3\CMS\Core\Database\ConnectionPool\getConnectionParams().

◆ getConnectionNames()

TYPO3\CMS\Core\Database\ConnectionPool::getConnectionNames ( )

Returns an array containing the names of all currently configured connections.

This method should only be used in edge cases. Use getConnectionForTable() so that the tablename<>databaseConnection mapping will be taken into account.

Definition at line 325 of file ConnectionPool.php.

References $GLOBALS.

◆ getConnectionParams()

TYPO3\CMS\Core\Database\ConnectionPool::getConnectionParams ( string  $connectionName)
protected

◆ getDatabaseConnection()

TYPO3\CMS\Core\Database\ConnectionPool::getDatabaseConnection ( string  $connectionName,
array  $connectionParams 
)
protected

◆ getDriverMiddlewares()

TYPO3\CMS\Core\Database\ConnectionPool::getDriverMiddlewares ( string  $connectionName,
array  $connectionParams 
)
protected

Return any doctrine driver middlewares, that may have been set up in:

  • ‪for all configured connections
  • ‪$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['driverMiddlewares'] for a specific connection

Definition at line 176 of file ConnectionPool.php.

References TYPO3\CMS\Core\Database\ConnectionPool\$driverMiddlewares.

Referenced by TYPO3\CMS\Core\Database\ConnectionPool\getDatabaseConnection().

◆ getQueryBuilderForTable()

TYPO3\CMS\Core\Database\ConnectionPool::getQueryBuilderForTable ( string  $tableName)

Returns the connection specific query builder object that can be used to build complex SQL queries using and object-oriented approach.

Definition at line 305 of file ConnectionPool.php.

References TYPO3\CMS\Core\Database\ConnectionPool\getConnectionForTable().

Referenced by TYPO3\CMS\Impexp\Domain\Repository\PresetRepository\__construct().

◆ registerDoctrineTypes()

TYPO3\CMS\Core\Database\ConnectionPool::registerDoctrineTypes ( )

Register custom and override Doctrine data types implemented by TYPO3. This method is needed by Schema parser to register the types as it does not require a database connection and thus the types don't get registered automatically.

Definition at line 338 of file ConnectionPool.php.

Referenced by TYPO3\CMS\Core\Database\ConnectionPool\getDatabaseConnection().

◆ resetConnections()

TYPO3\CMS\Core\Database\ConnectionPool::resetConnections ( )

Reset internal list of connections. Currently, primarily used in functional tests to close connections and start new ones in between single tests.

Definition at line 361 of file ConnectionPool.php.

Member Data Documentation

◆ $connections

Connection [] TYPO3\CMS\Core\Database\ConnectionPool::$connections = array( )
staticprotected

Definition at line 54 of file ConnectionPool.php.

◆ $customDoctrineTypes

array TYPO3\CMS\Core\Database\ConnectionPool::$customDoctrineTypes
protected
Initial value:
= [
‪EnumType::TYPE => EnumType::class,
‪SetType::TYPE => SetType::class,
]

Definition at line 59 of file ConnectionPool.php.

◆ $driverMiddlewares [1/2]

TYPO3\CMS\Core\Database\ConnectionPool::$driverMiddlewares[ $identifier][ 'type'] = 'global'

◆ $driverMiddlewares [2/2]

foreach ( $connectionParams[ 'driverMiddlewares'] ??[] as $identifier=> $middleware) TYPO3\CMS\Core\Database\ConnectionPool::$driverMiddlewares
Initial value:
= array_filter(‪$driverMiddlewares, static function (array $middleware) use ($connectionName, $connectionParams): bool {
$className = $middleware['target'];
$classImplements = class_exists($className) ? (class_implements($className) ?: []) : [];
if (!in_array(DriverMiddleware::class, $classImplements, true)) {
throw new \UnexpectedValueException(
sprintf(
'Doctrine Driver Middleware "%s" must implement \Doctrine\DBAL\Driver\Middleware',
$className
),
1677958727
);
}
if (in_array(UsableForConnectionInterface::class, $classImplements, true)) {
return GeneralUtility::makeInstance($middleware['target'])->canBeUsedForConnection($connectionName, $connectionParams);
}
return true;
})

Definition at line 244 of file ConnectionPool.php.

◆ $overrideDoctrineTypes

array TYPO3\CMS\Core\Database\ConnectionPool::$overrideDoctrineTypes
protected
Initial value:
= [
Types::DATE_MUTABLE => DateType::class,
Types::DATETIME_MUTABLE => DateTimeType::class,
Types::DATETIME_IMMUTABLE => DateTimeType::class,
Types::TIME_MUTABLE => TimeType::class,
]

Definition at line 67 of file ConnectionPool.php.

◆ DEFAULT_CONNECTION_NAME

const TYPO3\CMS\Core\Database\ConnectionPool::DEFAULT_CONNECTION_NAME = 'Default'

Definition at line 50 of file ConnectionPool.php.

Referenced by TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\addNewColumns(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\changeExistingColumn(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\changeExistingIndex(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\changeTableEngine(), TYPO3\CMS\Install\Controller\InstallerController\checkDatabaseDataAction(), TYPO3\CMS\Install\Controller\InstallerController\checkDatabaseRequirementsAction(), TYPO3\CMS\Install\Service\SetupDatabaseService\checkDatabaseSelect(), TYPO3\CMS\Install\Service\SetupDatabaseService\checkExistingDatabase(), TYPO3\CMS\Install\Service\SetupDatabaseService\createDatabase(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\createNewTable(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\createNewTableIfNotExists(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\defaultNullWithoutNotNull(), TYPO3\CMS\Core\Tests\Functional\Database\Middleware\CustomPlatformDriverMiddlewareTest\driverMiddlewareIsRegistered(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\dropUnusedField(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\dropUnusedTable(), TYPO3\CMS\Backend\Tests\Functional\Utility\BackendUtilityTest\enableFieldsStatementIsCorrect(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\ensureThatExpectedQuoteCharUsedInUnquoteIsValid(), TYPO3\CMS\Install\Database\PermissionsCheck\getConnection(), TYPO3\CMS\Core\Database\ConnectionPool\getConnectionForTable(), TYPO3\CMS\Install\Service\SetupDatabaseService\getDatabaseList(), TYPO3\CMS\Adminpanel\Modules\Debug\QueryInformation\getDataToStore(), TYPO3\CMS\Install\Service\SetupDatabaseService\getDefaultSocketFor(), TYPO3\CMS\Install\Service\SetupDatabaseService\getDriverOptions(), TYPO3\CMS\Reports\Report\Status\ConfigurationStatus\getMysqlDatabaseUtf8Status(), TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend\getObjectDataByRawQuery(), TYPO3\CMS\Scheduler\Task\OptimizeDatabaseTableAdditionalFieldProvider\getOptimizableTables(), TYPO3\CMS\Install\Service\SetupDatabaseService\isDatabaseConfigurationComplete(), TYPO3\CMS\Install\Service\SetupDatabaseService\isDatabaseConnectSuccessful(), TYPO3\CMS\Reports\Report\Status\ConfigurationStatus\isMysqlUsed(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\jsonFieldDefaultValueTest(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\leftPadReturnsExpectedResult(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\leftPadWithEmptyStringPaddingValueThrowsInvalidArgumentException(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\leftPadWithMultiCharacterPaddingValueThrowsInvalidArgumentException(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\leftPadWithValueSubexpressionReturnsExpectedResult(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\leftReturnsExpectedResult(), TYPO3\CMS\Lowlevel\Controller\DatabaseIntegrityController\menuConfig(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\notNullWithoutDefaultValue(), TYPO3\CMS\Adminpanel\Middleware\SqlLogging\process(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\renameUnusedField(), TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\renameUnusedTable(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\repeatReturnsExpectedResult(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\repeatWithValueExpressionReturnsExpectedResult(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\rightPadReturnsExpectedResult(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\rightPadReturnsWithQuotedAliasExpectedResult(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\rightPadWithEmptyStringPaddingValueThrowsInvalidArgumentException(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\rightPadWithMultiCharacterPaddingValueThrowsInvalidArgumentException(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\rightPadWithValueSubexpressionReturnsExpectedResult(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\rightPadWithValueSubexpressionWithQuotedAliasReturnsExpectedResult(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\rightReturnsExpectedResult(), TYPO3\CMS\Core\Tests\Functional\Database\Query\Expression\ExpressionBuilderTest\spaceReturnsCorrectNumberOfSpaces(), and TYPO3\CMS\Core\Tests\Functional\Database\Schema\SchemaMigratorTest\textFieldDefaultValueTest().

‪TYPO3\CMS\Core\Database\Schema\Types\EnumType\TYPE
‪const TYPE
Definition: EnumType.php:30
‪TYPO3\CMS\Core\Database\ConnectionPool\$driverMiddlewares
‪$driverMiddlewares[$identifier]['type']
Definition: ConnectionPool.php:230
‪TYPO3\CMS\Core\Database\Schema\Types\SetType\TYPE
‪const TYPE
Definition: SetType.php:30