class DatabaseManager implements ConnectionResolverInterface mixin Connection (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected Application $app

The application instance.

protected ConnectionFactory $factory

The database connection factory instance.

protected Connection> $connections

The active connection instances.

protected array<string,callable> $extensions

The custom connection resolvers.

protected callable $reconnector

The callback to be executed to reconnect to a database.

Methods

static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically pass methods to the default connection.

void
__construct(Application $app, ConnectionFactory $factory)

Create a new database manager instance.

connection(string|null $name = null)

Get a database connection instance.

build(array $config)

Build a database connection instance from the given configuration.

connectUsing(string $name, array $config, bool $force = false)

Get a database connection instance from the given configuration.

array
parseConnectionName(string $name)

Parse the connection into an array of the name and read / write type.

makeConnection(string $name)

Make the database connection instance.

array
configuration(string $name)

Get the configuration for a connection.

configure(Connection $connection, string $type)

Prepare the database connection instance.

void
dispatchConnectionEstablishedEvent(Connection $connection)

Dispatch the ConnectionEstablished event if the event dispatcher is available.

setPdoForType(Connection $connection, string|null $type = null)

Prepare the read / write mode for database connection instance.

void
purge(string|null $name = null)

Disconnect from the given database and remove from local cache.

void
disconnect(string|null $name = null)

Disconnect from the given database.

reconnect(string|null $name = null)

Reconnect to the given database.

mixed
usingConnection(string $name, callable $callback)

Set the default database connection for the callback execution.

refreshPdoConnections(string $name)

Refresh the PDO connections on a given connection.

string
getDefaultConnection()

Get the default connection name.

void
setDefaultConnection(string $name)

Set the default connection name.

string[]
supportedDrivers()

Get all of the supported drivers.

string[]
availableDrivers()

Get all of the drivers that are actually available.

void
extend(string $name, callable $resolver)

Register an extension connection resolver.

void
forgetExtension(string $name)

Remove an extension connection resolver.

Connection>
getConnections()

Return all of the created connections.

void
setReconnector(callable $reconnector)

Set the database reconnector callback.

$this
setApplication(Application $app)

Set the application instance used by the manager.

Details

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically pass methods to the default connection.

Parameters

string $method
array $parameters

Return Value

mixed

void __construct(Application $app, ConnectionFactory $factory)

Create a new database manager instance.

Parameters

Application $app
ConnectionFactory $factory

Return Value

void

ConnectionInterface connection(string|null $name = null)

Get a database connection instance.

Parameters

string|null $name

Return Value

ConnectionInterface

ConnectionInterface build(array $config)

Build a database connection instance from the given configuration.

Parameters

array $config

Return Value

ConnectionInterface

ConnectionInterface connectUsing(string $name, array $config, bool $force = false)

Get a database connection instance from the given configuration.

Parameters

string $name
array $config
bool $force

Return Value

ConnectionInterface

protected array parseConnectionName(string $name)

Parse the connection into an array of the name and read / write type.

Parameters

string $name

Return Value

array

protected Connection makeConnection(string $name)

Make the database connection instance.

Parameters

string $name

Return Value

Connection

protected array configuration(string $name)

Get the configuration for a connection.

Parameters

string $name

Return Value

array

Exceptions

InvalidArgumentException

protected Connection configure(Connection $connection, string $type)

Prepare the database connection instance.

Parameters

Connection $connection
string $type

Return Value

Connection

protected void dispatchConnectionEstablishedEvent(Connection $connection)

Dispatch the ConnectionEstablished event if the event dispatcher is available.

Parameters

Connection $connection

Return Value

void

protected Connection setPdoForType(Connection $connection, string|null $type = null)

Prepare the read / write mode for database connection instance.

Parameters

Connection $connection
string|null $type

Return Value

Connection

void purge(string|null $name = null)

Disconnect from the given database and remove from local cache.

Parameters

string|null $name

Return Value

void

void disconnect(string|null $name = null)

Disconnect from the given database.

Parameters

string|null $name

Return Value

void

Connection reconnect(string|null $name = null)

Reconnect to the given database.

Parameters

string|null $name

Return Value

Connection

mixed usingConnection(string $name, callable $callback)

Set the default database connection for the callback execution.

Parameters

string $name
callable $callback

Return Value

mixed

protected Connection refreshPdoConnections(string $name)

Refresh the PDO connections on a given connection.

Parameters

string $name

Return Value

Connection

string getDefaultConnection()

Get the default connection name.

Return Value

string

void setDefaultConnection(string $name)

Set the default connection name.

Parameters

string $name

Return Value

void

string[] supportedDrivers()

Get all of the supported drivers.

Return Value

string[]

string[] availableDrivers()

Get all of the drivers that are actually available.

Return Value

string[]

void extend(string $name, callable $resolver)

Register an extension connection resolver.

Parameters

string $name
callable $resolver

Return Value

void

void forgetExtension(string $name)

Remove an extension connection resolver.

Parameters

string $name

Return Value

void

Connection> getConnections()

Return all of the created connections.

Return Value

Connection>

void setReconnector(callable $reconnector)

Set the database reconnector callback.

Parameters

callable $reconnector

Return Value

void

$this setApplication(Application $app)

Set the application instance used by the manager.

Parameters

Application $app

Return Value

$this