public static function factory(array $dbConfig): DbItf
    {
        /** @var DbItf[] $instances */
        static $instances = [];

        $key = md5(json_encode($dbConfig));

        if (isset($instances[$key])) {
            return $instances[$key];
        }

        switch ($dbConfig[DbItf::DB_CFG_DRIVER]) {
            case DbItf::DB_DRIVER_MYSQL:
                $instances[$key] = new MySQL();
                $dbConfig[DbItf::DB_CFG_PORT] = (int)$dbConfig[DbItf::DB_CFG_PORT];
                break;

            default:
                throw new DatabaseEx('Unknown database driver name: ' . $dbConfig[DbItf::DB_CFG_DRIVER]);
        }

        $instances[$key]->dbSetup($dbConfig);

        if ($dbConfig[DbItf::DB_CFG_CONNECT]) {
            $instances[$key]->dbConnect();
        }

        return $instances[$key];
    }
public static function factory(array $dbConfig): DbItf
    {
        /** @var DbItf[] $instances */
        static $instances = [];

        $key = md5(json_encode($dbConfig));

        if (isset($instances[$key])) {
            return $instances[$key];
        }

        switch ($dbConfig[DbItf::DB_CFG_DRIVER]) {
            case DbItf::DB_DRIVER_MYSQL:
                $instances[$key] = new MySQL();
                $dbConfig[DbItf::DB_CFG_PORT] = (int)$dbConfig[DbItf::DB_CFG_PORT];
                break;

            default:
                throw new DatabaseEx('Unknown database driver name: ' . $dbConfig[DbItf::DB_CFG_DRIVER]);
        }

        $instances[$key]->dbSetup($dbConfig);

        if ($dbConfig[DbItf::DB_CFG_CONNECT]) {
            $instances[$key]->dbConnect();
        }

        return $instances[$key];
    }
public static function factory ( array $ dbConfig ) : DbItf { /** @var DbItf[] $instances */ static $ instances = [ ] ; $ key = md5 ( json_encode ( $ dbConfig ) ) ; if ( isset ( $ instances [ $ key ] ) ) { return $ instances [ $ key ] ; } switch ( $ dbConfig [ DbItf :: DB_CFG_DRIVER ] ) { case DbItf :: DB_DRIVER_MYSQL : $ instances [ $ key ] = new MySQL ( ) ; $ dbConfig [ DbItf :: DB_CFG_PORT ] = ( int ) $ dbConfig [ DbItf :: DB_CFG_PORT ] ; break ; default : throw new DatabaseEx ( 'Unknown database driver name: ' . $ dbConfig [ DbItf :: DB_CFG_DRIVER ] ) ; } $ instances [ $ key ] -> dbSetup ( $ dbConfig ) ; if ( $ dbConfig [ DbItf :: DB_CFG_CONNECT ] ) { $ instances [ $ key ] -> dbConnect ( ) ; } return $ instances [ $ key ] ; }
Database factory.

It returns the same instance for the same config.

@param array $dbConfig The database configuration

@throws DatabaseEx

@return DbItf
Database factory .