1 | <?php |
||
19 | class NativeFileSystem implements FileSystem |
||
20 | { |
||
21 | const EXTENSION = '.dbdata'; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $baseDir; |
||
27 | |||
28 | /** |
||
29 | * NativeFileSystem constructor. |
||
30 | * |
||
31 | * @param $baseDir |
||
32 | */ |
||
33 | public function __construct($baseDir) |
||
43 | |||
44 | /** |
||
45 | * Reads a file from the file system. |
||
46 | * |
||
47 | * @param string $filePath |
||
48 | * |
||
49 | * @return mixed |
||
50 | */ |
||
51 | public function read($filePath) |
||
61 | |||
62 | /** |
||
63 | * @param $id |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | private function calculateFilePath($id) |
||
76 | |||
77 | /** |
||
78 | * Returns the base directory. |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public function baseDir() |
||
86 | |||
87 | /** |
||
88 | * @param string $key |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | private function getDirectoryHash($key) |
||
102 | |||
103 | /** |
||
104 | * Writes a file to the file system. |
||
105 | * |
||
106 | * @param string $filePath |
||
107 | * @param string $contents |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function write($filePath, $contents) |
||
118 | |||
119 | /** |
||
120 | * @param $filePath |
||
121 | */ |
||
122 | private function createDirectory($filePath) |
||
130 | |||
131 | /** |
||
132 | * Returns a flat array containing a list of files in a directory. |
||
133 | * Files are searched recursively. |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | public function files() |
||
145 | |||
146 | /** |
||
147 | * @param string $directory |
||
148 | * @param array $files |
||
149 | */ |
||
150 | private function filesRecursively($directory, array &$files) |
||
160 | |||
161 | /** |
||
162 | * Deletes a file from the file system. |
||
163 | * |
||
164 | * @param string $filePath |
||
165 | */ |
||
166 | public function delete($filePath) |
||
173 | |||
174 | /** |
||
175 | * @param string $filePath |
||
176 | * |
||
177 | * @return bool |
||
178 | */ |
||
179 | public function exists($filePath) |
||
183 | |||
184 | /** |
||
185 | * Deletes all file from the base directory given the current file system. |
||
186 | */ |
||
187 | public function deleteAll() |
||
192 | |||
193 | /** |
||
194 | * @param string $directory |
||
195 | */ |
||
196 | private function deleteAllRecursively($directory) |
||
210 | } |
||
211 |