SQLiteConnector.php
TLDR
This file SQLiteConnector.php
is a part of the Illuminate\Database\Connectors
namespace in the Demo Projects project. It contains a class named SQLiteConnector
which extends the Connector
class and implements the ConnectorInterface
interface. The class has a connect
method that establishes a connection with a SQLite database based on the given configuration.
Methods
connect
This method is responsible for establishing a database connection. It takes an array $config
as a parameter and returns a PDO
instance representing the connection.
If the database specified in the configuration is an in-memory database (i.e., :memory:
), it creates a connection to an in-memory database.
If the database specified is a file path, it verifies that the database file exists before creating a connection.
If the specified database file doesn't exist, it throws a SQLiteDatabaseDoesNotExistException
.
Classes
Class SQLiteConnector
This class extends the Connector
class and implements the ConnectorInterface
interface. It is responsible for connecting to a SQLite database based on the specified configuration.
That's all the information available in the provided file.
<?php
namespace Illuminate\Database\Connectors;
use Illuminate\Database\SQLiteDatabaseDoesNotExistException;
class SQLiteConnector extends Connector implements ConnectorInterface
{
/**
* Establish a database connection.
*
* @param array $config
* @return \PDO
*
* @throws \Illuminate\Database\SQLiteDatabaseDoesNotExistException
*/
public function connect(array $config)
{
$options = $this->getOptions($config);
// SQLite supports "in-memory" databases that only last as long as the owning
// connection does. These are useful for tests or for short lifetime store
// querying. In-memory databases may only have a single open connection.
if ($config['database'] === ':memory:') {
return $this->createConnection('sqlite::memory:', $config, $options);
}
$path = realpath($config['database']);
// Here we'll verify that the SQLite database exists before going any further
// as the developer probably wants to know if the database exists and this
// SQLite driver will not throw any exception if it does not by default.
if ($path === false) {
throw new SQLiteDatabaseDoesNotExistException($config['database']);
}
return $this->createConnection("sqlite:{$path}", $config, $options);
}
}