-
Notifications
You must be signed in to change notification settings - Fork 1
/
Connector.php
50 lines (42 loc) · 1.08 KB
/
Connector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Tivins\Database\Connectors;
use PDO;
use PDOException;
use Tivins\Database\Exceptions\ConnectionException;
/**
* Abstract class used by all connectors for Database.
*
* The connector need to create a new PDO handler.
*/
abstract class Connector
{
protected ConnectorType $connectorType = ConnectorType::NONE;
/**
* Try the connector to get a valid PDO object.
*
* This function is called by the Database to get the PDO handler.
*
* @throws ConnectionException
*/
public function connect(): PDO
{
try {
return $this->createHandler();
} catch (PDOException $pdoException) {
throw new ConnectionException($pdoException->getMessage());
}
}
/**
* Return a valid PDO object.
*/
abstract public function createHandler(): PDO;
/**
* Get the 'show tables' query for the selector.
* @return string
*/
abstract public function getShowTablesQuery(): string;
public function getType(): ConnectorType
{
return $this->connectorType;
}
}