1 | <?php |
||
31 | final class Database |
||
32 | { |
||
33 | const CONFIG_LOCALE = 'locale'; |
||
34 | |||
35 | private $connection; |
||
36 | private $scheme; |
||
37 | private $tables = []; |
||
38 | private $tablesClasses = []; |
||
39 | private $inTransaction = false; |
||
40 | private $onExecute; |
||
41 | private $config = []; |
||
42 | private $fieldFactories = []; |
||
43 | |||
44 | public function __construct(PDO $pdo, SchemeInterface $scheme = null, array $fieldFactories = null) |
||
67 | |||
68 | /** |
||
69 | * Configure custom classes for some tables |
||
70 | * [table => classname] |
||
71 | */ |
||
72 | public function setTablesClasses(array $classes): self |
||
78 | |||
79 | /** |
||
80 | * Returns a config value |
||
81 | */ |
||
82 | public function getConfig(string $name) |
||
86 | |||
87 | /** |
||
88 | * Set a config value |
||
89 | * @param mixed $value |
||
90 | */ |
||
91 | public function setConfig(string $name, $value): self |
||
97 | |||
98 | /** |
||
99 | * Return the scheme class |
||
100 | */ |
||
101 | public function getScheme(): SchemeInterface |
||
105 | |||
106 | /** |
||
107 | * Returns the connection instance. |
||
108 | */ |
||
109 | public function getConnection(): Connection |
||
113 | |||
114 | public function select(): Select |
||
118 | |||
119 | public function update(): Update |
||
123 | |||
124 | public function delete(): Delete |
||
128 | |||
129 | public function insert(): Insert |
||
133 | |||
134 | public function setFieldFactory(FieldFactory $fieldFactory): self |
||
140 | |||
141 | public function getFieldFactory(string $className): FieldFactory |
||
145 | |||
146 | public function getFieldFactories(): array |
||
150 | |||
151 | /** |
||
152 | * Clear the cache of all tables |
||
153 | */ |
||
154 | public function clearCache(): self |
||
162 | |||
163 | /** |
||
164 | * Magic method to initialize the tables in lazy mode. |
||
165 | * |
||
166 | * @throws SimpleCrudException If the table cannot be instantiated |
||
167 | */ |
||
168 | public function __get(string $name): Table |
||
184 | |||
185 | /** |
||
186 | * Magic method to check if a table exists or not. |
||
187 | */ |
||
188 | public function __isset(string $name): bool |
||
192 | |||
193 | /** |
||
194 | * Execute a query and returns the statement object with the result. |
||
195 | * |
||
196 | * @throws Exception |
||
197 | */ |
||
198 | public function execute(string $query, array $marks = null): PDOStatement |
||
205 | |||
206 | /** |
||
207 | * Execute a callable inside a transaction. |
||
208 | * |
||
209 | * @return mixed The callable returned value |
||
210 | */ |
||
211 | public function executeTransaction(callable $callable) |
||
231 | |||
232 | /** |
||
233 | * Returns the last insert id. |
||
234 | */ |
||
235 | public function lastInsertId(): string |
||
239 | |||
240 | /** |
||
241 | * Starts a transaction if it's not started yet. |
||
242 | */ |
||
243 | public function beginTransaction(): bool |
||
253 | |||
254 | /** |
||
255 | * Commits the changes of the transaction to the database. |
||
256 | */ |
||
257 | public function commit() |
||
264 | |||
265 | /** |
||
266 | * RollBack a transaction. |
||
267 | */ |
||
268 | public function rollBack() |
||
275 | |||
276 | /** |
||
277 | * Check if there is a transaction opened currently in this adapter. |
||
278 | */ |
||
279 | public function inTransaction() |
||
283 | |||
284 | private static function createDefaultFieldFactories(): array |
||
300 | } |
||
301 |