class ConnectionFactory (View source)

Properties

protected Container $container

The IoC container instance.

Methods

void
__construct(Container $container)

Create a new connection factory instance.

make(array $config, string|null $name = null)

Establish a PDO connection based on the configuration.

array
parseConfig(array $config, string $name)

Parse and prepare the database configuration.

createSingleConnection(array $config)

Create a single database connection instance.

createReadWriteConnection(array $config)

Create a read / write database connection instance.

createReadPdo(array $config)

Create a new PDO instance for reading.

array
getReadConfig(array $config)

Get the read configuration for a read / write connection.

array
getWriteConfig(array $config)

Get the write configuration for a read / write connection.

array
getReadWriteConfig(array $config, string $type)

Get a read / write level configuration.

array
mergeReadWriteConfig(array $config, array $merge)

Merge a configuration for a read / write connection.

createPdoResolver(array $config)

Create a new Closure that resolves to a PDO instance.

createPdoResolverWithHosts(array $config)

Create a new Closure that resolves to a PDO instance with a specific host or an array of hosts.

array
parseHosts(array $config)

Parse the hosts configuration item into an array.

createPdoResolverWithoutHosts(array $config)

Create a new Closure that resolves to a PDO instance where there is no configured host.

createConnector(array $config)

Create a connector instance based on the configuration.

createConnection(string $driver, PDO|Closure $connection, string $database, string $prefix = '', array $config = [])

Create a new connection instance.

Details

void __construct(Container $container)

Create a new connection factory instance.

Parameters

Container $container

Return Value

void

Connection make(array $config, string|null $name = null)

Establish a PDO connection based on the configuration.

Parameters

array $config
string|null $name

Return Value

Connection

protected array parseConfig(array $config, string $name)

Parse and prepare the database configuration.

Parameters

array $config
string $name

Return Value

array

protected Connection createSingleConnection(array $config)

Create a single database connection instance.

Parameters

array $config

Return Value

Connection

protected Connection createReadWriteConnection(array $config)

Create a read / write database connection instance.

Parameters

array $config

Return Value

Connection

protected Closure createReadPdo(array $config)

Create a new PDO instance for reading.

Parameters

array $config

Return Value

Closure

protected array getReadConfig(array $config)

Get the read configuration for a read / write connection.

Parameters

array $config

Return Value

array

protected array getWriteConfig(array $config)

Get the write configuration for a read / write connection.

Parameters

array $config

Return Value

array

protected array getReadWriteConfig(array $config, string $type)

Get a read / write level configuration.

Parameters

array $config
string $type

Return Value

array

protected array mergeReadWriteConfig(array $config, array $merge)

Merge a configuration for a read / write connection.

Parameters

array $config
array $merge

Return Value

array

protected Closure createPdoResolver(array $config)

Create a new Closure that resolves to a PDO instance.

Parameters

array $config

Return Value

Closure

protected Closure createPdoResolverWithHosts(array $config)

Create a new Closure that resolves to a PDO instance with a specific host or an array of hosts.

Parameters

array $config

Return Value

Closure

Exceptions

PDOException

protected array parseHosts(array $config)

Parse the hosts configuration item into an array.

Parameters

array $config

Return Value

array

Exceptions

InvalidArgumentException

protected Closure createPdoResolverWithoutHosts(array $config)

Create a new Closure that resolves to a PDO instance where there is no configured host.

Parameters

array $config

Return Value

Closure

ConnectorInterface createConnector(array $config)

Create a connector instance based on the configuration.

Parameters

array $config

Return Value

ConnectorInterface

Exceptions

InvalidArgumentException

protected Connection createConnection(string $driver, PDO|Closure $connection, string $database, string $prefix = '', array $config = [])

Create a new connection instance.

Parameters

string $driver
PDO|Closure $connection
string $database
string $prefix
array $config

Return Value

Connection

Exceptions

InvalidArgumentException