class ConnectionResolver implements ConnectionResolverInterface

Resolves database connections from a connection pool.

Retains pooled wrappers until their owning coroutine or task ends.

Constants

DEFAULT_CONNECTION_CONTEXT_KEY

Context key for per-coroutine default connection override.

Shared with DatabaseManager::usingConnection() to ensure all access paths respect the override.

Properties

protected string|null $default

The config-derived default connection name, captured at construction.

protected PoolFactory $factory
protected PooledConnection> $nonCoroutineConnections

Pooled wrappers retained by non-coroutine task execution.

Methods

__construct(Container $container)

No description

connection(UnitEnum|string|null $name = null)

Get a database connection instance.

void
releaseConnections()

Release connections retained by non-coroutine task execution.

void
discardConnections()

Discard connections retained by non-coroutine task execution.

string|null
getDefaultConnection()

Get the default connection name.

void
setDefaultConnection(string|null $name)

Set the default connection name for the current execution context.

string
getContextKey(string $name)

Get the context key for storing a connection.

void
terminateConnections(Closure $terminate)

Detach and terminate retained non-coroutine connections.

Details

at line 51
__construct(Container $container)

No description

Parameters

Container $container

at line 65
ConnectionInterface connection(UnitEnum|string|null $name = null)

Get a database connection instance.

The connection is retrieved from a pool and stored in the current coroutine's context. When the coroutine ends, the connection is automatically released back to the pool.

Parameters

UnitEnum|string|null $name

Return Value

ConnectionInterface

at line 149
void releaseConnections()

internal  
 

Release connections retained by non-coroutine task execution.

Return Value

void

at line 163
void discardConnections()

internal  
 

Discard connections retained by non-coroutine task execution.

Return Value

void

at line 179
string|null getDefaultConnection()

Get the default connection name.

Checks Context first for per-coroutine override (from setDefaultConnection() or DatabaseManager::usingConnection()), then falls back to the config-derived default captured at construction.

Return Value

string|null

at line 191
void setDefaultConnection(string|null $name)

Set the default connection name for the current execution context.

Writes to coroutine Context so concurrent requests in the same Swoole worker are not affected. A null value clears the override and getDefaultConnection() falls back to the config-derived default.

Parameters

string|null $name

Return Value

void

at line 203
protected string getContextKey(string $name)

Get the context key for storing a connection.

Parameters

string $name

Return Value

string

at line 211
protected void terminateConnections(Closure $terminate)

Detach and terminate retained non-coroutine connections.

Parameters

Closure $terminate

Return Value

void