ConnectionFactory
class ConnectionFactory
Properties
| protected array<string, callable> | $extensions | The custom connection resolvers. |
Methods
Establish a database connection based on the configuration.
Get the extension resolver for a connection configuration.
Register an extension connection resolver.
Remove an extension connection resolver.
Create an in-memory SQLite connection using a shared PDO.
Create the initial pooled in-memory SQLite connection.
Parse and prepare the database configuration.
Determine if the configuration has a read side.
Get the single-role read configuration for a read / write connection.
Create a PDO-backed connection from its configuration.
Create a single PDO-backed connection instance.
Create a read / write database connection instance.
Create a new PDO instance for reading.
Get the read configuration for a read / write connection.
Get the write configuration for a read / write connection.
Get a read / write level configuration.
Merge a configuration for a read / write connection.
Create a new Closure that resolves to a PDO instance.
Create a new Closure that resolves to a PDO instance with a specific host or an array of hosts.
Parse the hosts configuration item into an array.
Create a new Closure that resolves to a PDO instance where there is no configured host.
Create a connector instance based on the configuration.
Create a new connection instance.
Details
at line 35
__construct(Container $container)
Create a new connection factory instance.
at line 43
Connection
make(array $config, string|null $name = null)
Establish a database connection based on the configuration.
at line 71
callable|null
getExtension(array $config, string|null $name)
Get the extension resolver for a connection configuration.
at line 86
void
extend(string $name, callable $resolver)
Register an extension connection resolver.
Boot-only. The resolver persists in the singleton factory's extensions array for the worker lifetime and applies to every subsequent connection.
at line 98
void
forgetExtension(string $name)
Remove an extension connection resolver.
Boot or tests only. Mutates the singleton factory's extensions array; concurrent coroutines establishing connections may see the resolver removed mid-resolution.
at line 112
PdoConnection
makeSqliteFromSharedPdo(PDO $pdo, array $config, string|null $name = null)
Create an in-memory SQLite connection using a shared PDO.
Used by connection pooling for in-memory SQLite where all pool slots must share the same PDO instance to see the same data. Without this, each pooled connection would get its own empty in-memory database.
Laravel-compatible PDO resolvers may return a custom PdoConnection subclass.
at line 135
PdoConnection
makeSharedInMemorySqliteConnection(array $config, string|null $name = null)
Create the initial pooled in-memory SQLite connection.
at line 150
array
parseConfig(array $config, string|null $name)
Parse and prepare the database configuration.
at line 160
bool
hasReadConfig(array $config)
Determine if the configuration has a read side.
at line 168
array
configForRead(array $config)
Get the single-role read configuration for a read / write connection.
at line 184
protected PdoConnection
createPdoConnectionFromConfig(array $config)
Create a PDO-backed connection from its configuration.
at line 196
protected PdoConnection
createSingleConnection(array $config)
Create a single PDO-backed connection instance.
at line 212
protected PdoConnection
createReadWriteConnection(array $config)
Create a read / write database connection instance.
at line 224
protected Closure
createReadPdo(array $config)
Create a new PDO instance for reading.
at line 232
protected array
getReadConfig(array $config)
Get the read configuration for a read / write connection.
at line 246
protected array
getWriteConfig(array $config)
Get the write configuration for a read / write connection.
at line 260
protected array
getReadWriteConfig(array $config, string $type)
Get a read / write level configuration.
at line 270
protected array
mergeReadWriteConfig(array $config, array $merge)
Merge a configuration for a read / write connection.
at line 278
protected Closure
createPdoResolver(array $config)
Create a new Closure that resolves to a PDO instance.
at line 290
protected Closure
createPdoResolverWithHosts(array $config)
Create a new Closure that resolves to a PDO instance with a specific host or an array of hosts.
at line 316
protected array
parseHosts(array $config)
Parse the hosts configuration item into an array.
at line 330
protected Closure
createPdoResolverWithoutHosts(array $config)
Create a new Closure that resolves to a PDO instance where there is no configured host.
at line 340
ConnectorInterface
createConnector(array $config)
Create a connector instance based on the configuration.
at line 364
protected PdoConnection
createConnection(string $driver, PDO|Closure $connection, string $database, string $prefix = '', array $config = [])
Create a new connection instance.