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 PoolFactory | $factory | ||
| 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.
Details
at line 51
__construct(Container $container)
No description
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.
at line 149
void
releaseConnections()
| internal |
Release connections retained by non-coroutine task execution.
at line 163
void
discardConnections()
| internal |
Discard connections retained by non-coroutine task execution.
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.
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.
at line 203
protected string
getContextKey(string $name)
Get the context key for storing a connection.
at line 211
protected void
terminateConnections(Closure $terminate)
Detach and terminate retained non-coroutine connections.