Total Complexity | 5 |
Total Lines | 78 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
5 | class MicroDb |
||
6 | { |
||
7 | |||
8 | const EXTENSION = 'fdb'; |
||
9 | |||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $storageDir; |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $dbName; |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $type; |
||
22 | /** |
||
23 | * @var Factory |
||
24 | */ |
||
25 | protected $factory; |
||
26 | |||
27 | /** |
||
28 | * @param string $storageDir |
||
29 | * @param string $dbName |
||
30 | * @param string $type file or memory |
||
31 | * @param Factory $factory |
||
32 | */ |
||
33 | public function __construct(string $storageDir, string $dbName, string $type = 'file', Factory $factory = null) |
||
34 | { |
||
35 | $this->storageDir = \rtrim($storageDir, '/'); |
||
36 | $this->dbName = $this->normalize($dbName); |
||
37 | $this->setType($type); |
||
38 | $this->factory = $factory ?? new Factory(); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @param string $type file or memory |
||
43 | */ |
||
44 | public function setType(string $type) |
||
45 | { |
||
46 | $this->type = $type; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $collectionName |
||
51 | * |
||
52 | * @return Collection |
||
53 | */ |
||
54 | public function getCollection(string $collectionName): Collection |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param string $collectionName |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | protected function getCollectionFilePath(string $collectionName): string |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @param string $value |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | private function normalize(string $value): string |
||
86 |