1 | <?php |
||
18 | class Path |
||
19 | { |
||
20 | /** |
||
21 | * Path without trailing slashes. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | private $path; |
||
26 | |||
27 | /** |
||
28 | * Raw path, that could contain placeholders. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $pathRaw; |
||
33 | |||
34 | /** |
||
35 | * Part of path, that is not changing because of placeholders. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | private $pathNotChanging; |
||
40 | |||
41 | /** |
||
42 | * Indicates if the path changes over time. |
||
43 | * |
||
44 | * @var bool |
||
45 | */ |
||
46 | private $pathIsChanging = false; |
||
47 | |||
48 | /** |
||
49 | * List of all path elements. |
||
50 | * |
||
51 | * @var string[] |
||
52 | */ |
||
53 | private $pathElements = []; |
||
54 | |||
55 | /** |
||
56 | * Time for replacing placeholders |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | private $time; |
||
61 | |||
62 | /** |
||
63 | * Whether leading slash is needed or not |
||
64 | * |
||
65 | * @var bool |
||
66 | */ |
||
67 | private $isAbsolute; |
||
68 | |||
69 | /** |
||
70 | * Path constructor. |
||
71 | * |
||
72 | * @param string $path |
||
73 | * @param int|null $time |
||
74 | */ |
||
75 | 53 | public function __construct(string $path, $time = null) |
|
82 | |||
83 | /** |
||
84 | * Setup path |
||
85 | * |
||
86 | * @param string $path |
||
87 | */ |
||
88 | 53 | private function setupPath(string $path) |
|
102 | |||
103 | /** |
||
104 | * Find path elements that can't change because of placeholder usage. |
||
105 | * |
||
106 | * @param string $path |
||
107 | * @return string |
||
108 | */ |
||
109 | 11 | private function detectPathNotChanging(string $path) : string |
|
134 | |||
135 | /** |
||
136 | * Return path element at given index. |
||
137 | * |
||
138 | * @param int $index |
||
139 | * @return string |
||
140 | */ |
||
141 | 6 | public function getPathElementAtIndex(int $index): string |
|
145 | |||
146 | /** |
||
147 | * Return the full target path depth. |
||
148 | * |
||
149 | * @return int |
||
150 | */ |
||
151 | 11 | public function getPathDepth(): int |
|
155 | |||
156 | /** |
||
157 | * Return the path to the backup file. |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | 26 | public function getPath(): string |
|
165 | |||
166 | /** |
||
167 | * Return the path to the backup file. |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | 4 | public function getPathRaw(): string |
|
175 | |||
176 | /** |
||
177 | * Is dirname configured with any date placeholders. |
||
178 | * |
||
179 | * @return bool |
||
180 | */ |
||
181 | 3 | public function hasChangingPath(): bool |
|
185 | |||
186 | /** |
||
187 | * Return the part of the path that is not changing. |
||
188 | * |
||
189 | * @return string |
||
190 | */ |
||
191 | 13 | public function getPathThatIsNotChanging(): string |
|
195 | |||
196 | /** |
||
197 | * Return path when casted to string. |
||
198 | * |
||
199 | * @return string |
||
200 | */ |
||
201 | 2 | public function __toString() |
|
205 | } |
||
206 |