LazyRecord\ConfigLoader::buildDSNObject PHP Method

buildDSNObject() public static method

Convert data source config to DSN object.
public static buildDSNObject ( array $config ) : DSN
$config array
return LazyRecord\DSN\DSN
    public static function buildDSNObject(array $config)
    {
        // Build DSN connection string for PDO
        $dsn = new DSN($config['driver']);
        foreach (array('database', 'dbname') as $key) {
            if (isset($config[$key])) {
                $dsn->setAttribute('dbname', $config[$key]);
                break;
            }
        }
        if (isset($config['host'])) {
            $dsn->setAttribute('host', $config['host']);
        }
        if (isset($config['port'])) {
            $dsn->setAttribute('port', $config['port']);
        }
        return $dsn;
    }