ConnectionResolver
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 PoolManager | $poolManager | ||
| protected PooledConnection> | $nonCoroutineConnections | Pooled wrappers retained by non-coroutine task execution. |
Methods
Get a database connection instance.
Release connections retained by non-coroutine task execution.
Discard connections retained by non-coroutine task execution.
Get the default connection name.
Set the default connection name for the current execution context.
Get the context key for storing a connection.
Discard a failed connection while preserving cancellation precedence.
Details
at line 55
__construct(Container $container)
Create a new connection resolver instance.
at line 69
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.
at line 159
void
releaseConnections()
| internal |
Release connections retained by non-coroutine task execution.
at line 173
void
discardConnections()
| internal |
Discard connections retained by non-coroutine task execution.
at line 189
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.
at line 201
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.
at line 213
protected string
getContextKey(string $name)
Get the context key for storing a connection.
at line 221
protected void
discardFailedConnection(PooledConnection $pooledConnection, Throwable $exception)
Discard a failed connection while preserving cancellation precedence.
at line 237
protected void
terminateConnections(Closure $terminate)
Detach and terminate retained non-coroutine connections.