1 | <?php |
||
18 | class Path |
||
19 | { |
||
20 | /** |
||
21 | * Path |
||
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 permanent |
||
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 $leadingSlash; |
||
68 | |||
69 | /** |
||
70 | * Whether trailing slash is needed or not |
||
71 | * |
||
72 | * @var bool |
||
73 | */ |
||
74 | private $trailingSlash; |
||
75 | |||
76 | /** |
||
77 | * Path constructor. |
||
78 | * |
||
79 | * @param string $path |
||
80 | * @param int|null $time |
||
81 | * @param bool|null $leadingSlash |
||
82 | * @param bool|null $trailingSlash |
||
83 | */ |
||
84 | 53 | public function __construct(string $path, $time = null, $leadingSlash = null, $trailingSlash = null) |
|
93 | |||
94 | /** |
||
95 | * Updates path according to provided parameters. |
||
96 | */ |
||
97 | 53 | private function setUp() |
|
126 | |||
127 | /** |
||
128 | * Find path elements that can't change because of placeholder usage. |
||
129 | * |
||
130 | * @param string $path |
||
131 | */ |
||
132 | 11 | private function detectPathNotChanging(string $path) |
|
156 | |||
157 | /** |
||
158 | * Return path element at given index. |
||
159 | * |
||
160 | * @param int $index |
||
161 | * @return string |
||
162 | */ |
||
163 | 6 | public function getPathElementAtIndex(int $index): string |
|
167 | |||
168 | /** |
||
169 | * Return the full target path depth. |
||
170 | * |
||
171 | * @return int |
||
172 | */ |
||
173 | 11 | public function getPathDepth(): int |
|
177 | |||
178 | /** |
||
179 | * Return the path to the backup file. |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | 26 | public function getPath(): string |
|
187 | |||
188 | /** |
||
189 | * Return the path to the backup file. |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | 4 | public function getPathRaw(): string |
|
197 | |||
198 | /** |
||
199 | * Is dirname configured with any date placeholders. |
||
200 | * |
||
201 | * @return bool |
||
202 | */ |
||
203 | 3 | public function hasChangingPath(): bool |
|
207 | |||
208 | /** |
||
209 | * Return the part of the path that is not changing. |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | 13 | public function getPathThatIsNotChanging(): string |
|
217 | |||
218 | /** |
||
219 | * Return path when casted to string. |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | 2 | public function __toString() |
|
227 | } |
||
228 |