Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
73.33% |
11 / 15 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
AppDatabaseConnection | |
73.33% |
11 / 15 |
|
66.67% |
2 / 3 |
4.30 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
getSqliteFilePath | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
open | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models; |
6 | |
7 | use PeServer\Core\Database\ConnectionSetting; |
8 | use PeServer\Core\Database\DatabaseConnection; |
9 | use PeServer\Core\Database\DatabaseContext; |
10 | use PeServer\Core\Log\ILoggerFactory; |
11 | use PeServer\Core\Text; |
12 | use PeServer\Core\Throws\InvalidOperationException; |
13 | |
14 | class AppDatabaseConnection extends DatabaseConnection |
15 | { |
16 | public function __construct( |
17 | AppConfiguration $config, |
18 | ILoggerFactory $loggerFactory |
19 | ) { |
20 | $persistence = $config->setting->persistence->default; |
21 | $connectionSetting = new ConnectionSetting( |
22 | $persistence->connection, |
23 | $persistence->user, |
24 | $persistence->password, |
25 | [] |
26 | ); |
27 | |
28 | parent::__construct($connectionSetting, $loggerFactory); |
29 | } |
30 | |
31 | #region DatabaseConnection |
32 | |
33 | public static function getSqliteFilePath(string $connection): string |
34 | { |
35 | list($db, $target) = Text::split($connection, ':', 2); |
36 | |
37 | if ($db !== 'sqlite') { |
38 | throw new InvalidOperationException($db); |
39 | } |
40 | |
41 | return $target; |
42 | } |
43 | |
44 | #endregion |
45 | |
46 | #region DatabaseConnection |
47 | |
48 | public function open(): DatabaseContext |
49 | { |
50 | $database = parent::open(); |
51 | |
52 | $database->execute('PRAGMA foreign_keys = ON;'); |
53 | |
54 | return $database; |
55 | } |
56 | |
57 | #endregion |
58 | } |