public static function fromArray(array $config)
    {
        if (!isset($config['engine'])) {
            throw new \InvalidArgumentException("Missing engine: must be either 'mysql' or 'sqlite'");
        }

        if (!in_array(strtolower($config['engine']), ['sqlite', 'mysql'])) {
            throw new \InvalidArgumentException("Unsupported engine {$config['engine']}");
        }

        if ($config['engine'] === 'sqlite') {
            return static::sqlite(
                $config['file'],
                $config['options'] ?? []
            );
        }

        if ($config['engine'] === 'mysql') {
            return static::mysql(
                $config['host'],
                $config['name'],
                $config['user'] ?? null,
                $config['pass'] ?? null,
                $config['options'] ?? []
            );
        }

        return null;
    }
public static function fromArray(array $config)
    {
        if (!isset($config['engine'])) {
            throw new \InvalidArgumentException("Missing engine: must be either 'mysql' or 'sqlite'");
        }

        if (!in_array(strtolower($config['engine']), ['sqlite', 'mysql'])) {
            throw new \InvalidArgumentException("Unsupported engine {$config['engine']}");
        }

        if ($config['engine'] === 'sqlite') {
            return static::sqlite(
                $config['file'],
                $config['options'] ?? []
            );
        }

        if ($config['engine'] === 'mysql') {
            return static::mysql(
                $config['host'],
                $config['name'],
                $config['user'] ?? null,
                $config['pass'] ?? null,
                $config['options'] ?? []
            );
        }

        return null;
    }
public static function fromArray ( array $ config ) { if ( ! isset ( $ config [ 'engine' ] ) ) { throw new \ InvalidArgumentException ( "Missing engine: must be either 'mysql' or 'sqlite'" ) ; } if ( ! in_array ( strtolower ( $ config [ 'engine' ] ) , [ 'sqlite' , 'mysql' ] ) ) { throw new \ InvalidArgumentException ( "Unsupported engine {$config['engine']}" ) ; } if ( $ config [ 'engine' ] === 'sqlite' ) { return static :: sqlite ( $ config [ 'file' ] , $ config [ 'options' ] ?? [ ] ) ; } if ( $ config [ 'engine' ] === 'mysql' ) { return static :: mysql ( $ config [ 'host' ] , $ config [ 'name' ] , $ config [ 'user' ] ?? null , $ config [ 'pass' ] ?? null , $ config [ 'options' ] ?? [ ] ) ; } return null ; }
Create a database connection to SQLite ot MySQL, based on a configuration array.

Array keys are as follows:

engine  | required |             | Either 'mysql' or 'sqlite
file    | required | SQLite only | Path and filename or ':memory:'
host    | required | MySQL only  | MySQL host name or IP address
name    | required | MySQL only  | Schema name
user    | optional | MySQL only  | Username
pass    | optional | MySQL only  | Password
options | optional |             | Additional PDO connection options

@param array $config
@return \ifcanduela\db\Database|null
Create a database connection to SQLite ot MySQL based on a configuration array .