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) |
||
68 | |||
69 | /** |
||
70 | * Configure custom classes for some tables |
||
71 | * [table => classname] |
||
72 | */ |
||
73 | public function setTablesClasses(array $classes): self |
||
79 | |||
80 | /** |
||
81 | * Returns a config value |
||
82 | */ |
||
83 | public function getConfig(string $name) |
||
87 | |||
88 | /** |
||
89 | * Set a config value |
||
90 | * @param mixed $value |
||
91 | */ |
||
92 | public function setConfig(string $name, $value): self |
||
98 | |||
99 | /** |
||
100 | * Return the scheme class |
||
101 | */ |
||
102 | public function getScheme(): SchemeInterface |
||
106 | |||
107 | /** |
||
108 | * Returns the connection instance. |
||
109 | */ |
||
110 | public function getConnection(): Connection |
||
114 | |||
115 | public function select(): Select |
||
119 | |||
120 | public function update(): Update |
||
124 | |||
125 | public function delete(): Delete |
||
129 | |||
130 | public function insert(): Insert |
||
134 | |||
135 | public function setFieldFactory(FieldFactory $fieldFactory): self |
||
141 | |||
142 | public function getFieldFactory(string $className): FieldFactory |
||
146 | |||
147 | public function getFieldFactories(): array |
||
151 | |||
152 | /** |
||
153 | * Magic method to initialize the tables in lazy mode. |
||
154 | * |
||
155 | * @throws SimpleCrudException If the table cannot be instantiated |
||
156 | */ |
||
157 | public function __get(string $name): Table |
||
173 | |||
174 | /** |
||
175 | * Magic method to check if a table exists or not. |
||
176 | */ |
||
177 | public function __isset(string $name): bool |
||
181 | |||
182 | /** |
||
183 | * Execute a query and returns the statement object with the result. |
||
184 | * |
||
185 | * @throws Exception |
||
186 | */ |
||
187 | public function execute(string $query, array $marks = null): PDOStatement |
||
194 | |||
195 | /** |
||
196 | * Execute a callable inside a transaction. |
||
197 | * |
||
198 | * @return mixed The callable returned value |
||
199 | */ |
||
200 | public function executeTransaction(callable $callable) |
||
220 | |||
221 | /** |
||
222 | * Returns the last insert id. |
||
223 | */ |
||
224 | public function lastInsertId(): string |
||
228 | |||
229 | /** |
||
230 | * Starts a transaction if it's not started yet. |
||
231 | */ |
||
232 | public function beginTransaction(): bool |
||
242 | |||
243 | /** |
||
244 | * Commits the changes of the transaction to the database. |
||
245 | */ |
||
246 | public function commit() |
||
253 | |||
254 | /** |
||
255 | * RollBack a transaction. |
||
256 | */ |
||
257 | public function rollBack() |
||
264 | |||
265 | /** |
||
266 | * Check if there is a transaction opened currently in this adapter. |
||
267 | */ |
||
268 | public function inTransaction() |
||
272 | |||
273 | private static function createDefaultFieldFactories(): array |
||
288 | } |
||
289 |