1<?php
2
3
4namespace ComboStrap;
5
6
7use DateTime;
8
9/**
10 * Class DokuFs
11 * @package ComboStrap
12 *
13 * The file system of Dokuwiki is based
14 * on drive name (such as page and media)
15 * that locates a directory on the local file system
16 */
17class DokuFs implements FileSystem
18{
19
20
21    public const SCHEME = 'doku';
22
23
24    /**
25     * @var DokuFs
26     */
27    private static $dokuFS;
28
29    public static function getOrCreate(): DokuFs
30    {
31        if (self::$dokuFS === null) {
32            self::$dokuFS = new DokuFs();
33        }
34        return self::$dokuFS;
35    }
36
37    /**
38     * @param DokuPath $path
39     */
40    function exists(Path $path): bool
41    {
42        $localAbsolutePath = $path->toLocalPath()->toAbsolutePath()->toString();
43        return file_exists($localAbsolutePath);
44    }
45
46    /**
47     * @param DokuPath $path
48     */
49    function getContent(Path $path)
50    {
51        return FileSystems::getContent($path->toLocalPath());
52    }
53
54    /**
55     * @param DokuPath $path
56     */
57    function getModifiedTime(Path $path): ?DateTime
58    {
59        return FileSystems::getModifiedTime($path->toLocalPath());
60    }
61
62    /**
63     * @param DokuPath $path
64     * @return DateTime|false|mixed|null
65     */
66    public function getCreationTime(Path $path)
67    {
68        return FileSystems::getCreationTime($path->toLocalPath());
69    }
70
71    /**
72     * @param DokuPath $path
73     */
74    public function delete(Path $path)
75    {
76        FileSystems::delete($path->toLocalPath());
77    }
78
79    /**
80     * @param DokuPath $path
81     */
82    public function getSize(Path $path)
83    {
84        return FileSystems::getSize($path->toLocalPath());
85    }
86
87    /**
88     * @param DokuPath $dirPath
89     * @return mixed
90     */
91    public function createDirectory(Path $dirPath)
92    {
93        return FileSystems::createDirectory($dirPath->toLocalPath());
94    }
95}
96