1 | <?php |
||
24 | abstract class AbstractDatabaseConnector { |
||
25 | |||
26 | /** |
||
27 | * Authenticator. |
||
28 | * |
||
29 | * @var Authenticator |
||
30 | */ |
||
31 | private $authenticator; |
||
32 | |||
33 | /** |
||
34 | * Connection. |
||
35 | * |
||
36 | * @var PDO |
||
37 | */ |
||
38 | private $connection; |
||
39 | |||
40 | /** |
||
41 | * Database. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private $database; |
||
46 | |||
47 | /** |
||
48 | * Constructor. |
||
49 | * |
||
50 | * @param Authenticator $authenticator The authenticator. |
||
51 | */ |
||
52 | protected function __construct(Authenticator $authenticator) { |
||
55 | |||
56 | /** |
||
57 | * Connect. |
||
58 | * |
||
59 | * @return PDO Returns the connection. |
||
60 | * @throws Exception Throws an exception if the connection failed. |
||
61 | */ |
||
62 | abstract protected function connect(); |
||
63 | |||
64 | /** |
||
65 | * Get the authenticator. |
||
66 | * |
||
67 | * @return Authenticator Returns the authenticator. |
||
68 | */ |
||
69 | public function getAuthenticator() { |
||
72 | |||
73 | /** |
||
74 | * Get the connection. |
||
75 | * |
||
76 | * @return PDO Returns the connection. |
||
77 | * @throws Exception Throws an exception if the connection failed. |
||
78 | */ |
||
79 | public function getConnection() { |
||
85 | |||
86 | /** |
||
87 | * Get the database. |
||
88 | * |
||
89 | * @return string Returns the database. |
||
90 | */ |
||
91 | public function getDatabase() { |
||
94 | |||
95 | /** |
||
96 | * Prepare a binding. |
||
97 | * |
||
98 | * @param array $fields The fields. |
||
99 | * @return array Returns the binding as key => :key. |
||
100 | */ |
||
101 | public function prepareBinding(array $fields) { |
||
108 | |||
109 | /** |
||
110 | * Prepare an INSERT SQL query. |
||
111 | * |
||
112 | * @param string $table The table. |
||
113 | * @param array $values The values [field => value]. |
||
114 | * @return string Returns the INSERT SQL query. |
||
115 | */ |
||
116 | public function prepareInsert($table, array $values) { |
||
130 | |||
131 | /** |
||
132 | * Prepare an UPDATE SQL query. |
||
133 | * |
||
134 | * @param string $table The table. |
||
135 | * @param array $values The values [field => value] |
||
136 | * @return string Returns the UPDATE SQL query. |
||
137 | */ |
||
138 | public function prepareUpdate($table, array $values) { |
||
154 | |||
155 | /** |
||
156 | * Set the authenticator. |
||
157 | * |
||
158 | * @param Authenticator $authenticator The authenticator. |
||
159 | * @return AbstractDatabase Returns this abstract database. |
||
160 | */ |
||
161 | protected function setAuthenticator(Authenticator $authenticator) { |
||
165 | |||
166 | /** |
||
167 | * Set the database. |
||
168 | * |
||
169 | * @param string $database The database. |
||
170 | * @return AbstractDatabase Returns this abstract database. |
||
171 | */ |
||
172 | protected function setDatabase($database) { |
||
176 | } |
||
177 |