-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathinit.php
More file actions
37 lines (30 loc) · 980 Bytes
/
init.php
File metadata and controls
37 lines (30 loc) · 980 Bytes
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
<?php
use Framework\Exceptions\DatabaseNotFound;
use Framework\ServiceContainer;
use Models\ItemCreator;
use Models\TagCreator;
// Bind DB services
ServiceContainer::bind(PDO::class, function () {
$db_path = Config::getDBPath();
if (!file_exists($db_path)) {
throw new DatabaseNotFound();
}
if (!is_writable($db_path)) {
throw new Exception("Database file not writable: {$db_path}");
}
$pdo = new PDO("sqlite:{$db_path}");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
});
ServiceContainer::bind(Models\Repository::class, function (): Models\Repository {
$pdo = ServiceContainer::get(PDO::class);
return new Models\Repository($pdo);
});
ServiceContainer::bind(TagCreator::class, function (): TagCreator {
$pdo = ServiceContainer::get(PDO::class);
return new TagCreator($pdo);
});
ServiceContainer::bind(ItemCreator::class, function (): ItemCreator {
$pdo = ServiceContainer::get(PDO::class);
return new ItemCreator($pdo);
});