0 follower

Final Class Yiisoft\Db\Connection\ConnectionProvider

InheritanceYiisoft\Db\Connection\ConnectionProvider

ConnectionProvider is used to manage DB connections.

Public Methods

Hide inherited methods

Method Description Defined By
all() Returns all connections. Yiisoft\Db\Connection\ConnectionProvider
clear() Clears all connections. Yiisoft\Db\Connection\ConnectionProvider
get() Returns a connection by name. Yiisoft\Db\Connection\ConnectionProvider
has() Checks if a connection with the given name exists. Yiisoft\Db\Connection\ConnectionProvider
remove() Removes a connection by name. Yiisoft\Db\Connection\ConnectionProvider
set() Sets a connection by name. Yiisoft\Db\Connection\ConnectionProvider

Constants

Hide inherited constants

Constant Value Description Defined By
DEFAULT 'default' Yiisoft\Db\Connection\ConnectionProvider

Method Details

Hide inherited methods

all() public static method

Returns all connections.

public static Yiisoft\Db\Connection\ConnectionInterface[] all ( )

                public static function all(): array
{
    return self::$connections;
}

            
clear() public static method

Clears all connections.

public static void clear ( )

                public static function clear(): void
{
    self::$connections = [];
}

            
get() public static method

Returns a connection by name.

public static Yiisoft\Db\Connection\ConnectionInterface get ( string $name self::DEFAULT )
$name string

                public static function get(string $name = self::DEFAULT): ConnectionInterface
{
    return self::$connections[$name]
        ?? throw new InvalidArgumentException("Connection with name '$name' does not exist.");
}

            
has() public static method

Checks if a connection with the given name exists.

public static boolean has ( string $name self::DEFAULT )
$name string

                public static function has(string $name = self::DEFAULT): bool
{
    return isset(self::$connections[$name]);
}

            
remove() public static method

Removes a connection by name.

public static void remove ( string $name self::DEFAULT )
$name string

                public static function remove(string $name = self::DEFAULT): void
{
    unset(self::$connections[$name]);
}

            
set() public static method

Sets a connection by name.

public static void set ( Yiisoft\Db\Connection\ConnectionInterface $connection, string $name self::DEFAULT )
$connection Yiisoft\Db\Connection\ConnectionInterface
$name string

                public static function set(ConnectionInterface $connection, string $name = self::DEFAULT): void
{
    self::$connections[$name] = $connection;
}