1 | <?php |
||
19 | class Filesystem extends \Symfony\Component\Filesystem\Filesystem |
||
20 | { |
||
21 | /** |
||
22 | * Build an absolute file or directory path separated by the OS specific directory separator. |
||
23 | * |
||
24 | * @param string ...$pathFragments |
||
25 | * |
||
26 | * @return string |
||
27 | */ |
||
28 | 49 | public function absolutePath($pathFragments) |
|
29 | { |
||
30 | 49 | if ($pathFragments instanceof FilesystemPath) |
|
31 | { |
||
32 | $pathFragments = (string)$pathFragments; |
||
|
|||
33 | } |
||
34 | |||
35 | 49 | if ($this->isAbsolutePath($pathFragments)) |
|
36 | { |
||
37 | return $pathFragments; |
||
38 | } |
||
39 | |||
40 | 49 | $args = func_get_args(); |
|
41 | 49 | array_unshift($args, Service::getWorkingDirectory()); |
|
42 | |||
43 | 49 | return implode(DIRECTORY_SEPARATOR, $args); |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * Build a file or directory path separated by the OS specific directory separator. |
||
48 | * |
||
49 | * @param string ...$pathFragments |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | 44 | public function appendPath($pathFragments) |
|
57 | |||
58 | /** |
||
59 | * Copy a file or folder recursively. |
||
60 | * |
||
61 | * @param string $originFile The original filename |
||
62 | * @param string $targetFile The target filename |
||
63 | * @param bool $overwriteNewerFiles If true, target files newer than origin files are overwritten |
||
64 | * |
||
65 | * @throws FileNotFoundException When originFile doesn't exist |
||
66 | * @throws IOException When copy fails |
||
67 | */ |
||
68 | public function copy($originFile, $targetFile, $overwriteNewerFiles = false) |
||
97 | |||
98 | /** |
||
99 | * Create an instance of stakx's File object with relative path information. |
||
100 | * |
||
101 | * @param string $filePath |
||
102 | * |
||
103 | * @return File |
||
104 | */ |
||
105 | public function createFileObject($filePath) |
||
109 | |||
110 | /** |
||
111 | * Strip the current working directory from an absolute path. |
||
112 | * |
||
113 | * @param string $path An absolute path |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 32 | public function getRelativePath($path) |
|
121 | |||
122 | /** |
||
123 | * Get the name of a given file without the extension. |
||
124 | * |
||
125 | * @param string $filePath A file path |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | 3 | public function getBaseName($filePath) |
|
133 | |||
134 | /** |
||
135 | * Get the name of a given file. |
||
136 | * |
||
137 | * @param string $filePath A file path |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | 1 | public function getFileName($filePath) |
|
142 | { |
||
143 | 1 | return pathinfo($filePath, PATHINFO_BASENAME); |
|
144 | } |
||
145 | |||
146 | /** |
||
147 | * Get the parent directory of a given file. |
||
148 | * |
||
149 | * @param string $filePath A file path |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | 15 | public function getFolderPath($filePath) |
|
157 | |||
158 | /** |
||
159 | * Get the extension of a given file. |
||
160 | * |
||
161 | * @param string $filename A file path |
||
162 | * |
||
163 | * @return string The extension of the file |
||
164 | */ |
||
165 | 35 | public function getExtension($filename) |
|
169 | |||
170 | /** |
||
171 | * Get the MIME type of a file. |
||
172 | * |
||
173 | * @param string $filePath |
||
174 | * |
||
175 | * @return string |
||
176 | */ |
||
177 | public function getMimeType($filePath) |
||
185 | |||
186 | /** |
||
187 | * Check whether or not if a given path is a directory. |
||
188 | * |
||
189 | * @param string $folderPath |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function isDir($folderPath) |
||
197 | |||
198 | /** |
||
199 | * Check whether or not a given path is a file. |
||
200 | * |
||
201 | * @param string $filePath |
||
202 | * |
||
203 | * @return bool |
||
204 | */ |
||
205 | public function isFile($filePath) |
||
209 | |||
210 | /** |
||
211 | * Check whether a given file path is a symlink. |
||
212 | * |
||
213 | * @param string $filePath |
||
214 | * |
||
215 | * @return bool |
||
216 | */ |
||
217 | public function isSymlink($filePath) |
||
221 | |||
222 | /** |
||
223 | * Get the full path to the file without the extension. |
||
224 | * |
||
225 | * @param string $filename A file path |
||
226 | * |
||
227 | * @return string |
||
228 | */ |
||
229 | 3 | public function removeExtension($filename) |
|
236 | |||
237 | 6 | public function path($path) |
|
241 | |||
242 | 2 | public function getInternalResource($name) |
|
248 | |||
249 | /** |
||
250 | * A vfsStream friendly way of getting the realpath() of something. |
||
251 | * |
||
252 | * @param string $path |
||
253 | * |
||
254 | * @return string |
||
255 | */ |
||
256 | 180 | public function realpath($path) |
|
260 | |||
261 | /** |
||
262 | * Check whether a given path is on the virtual filesystem. |
||
263 | * |
||
264 | * @param string $path |
||
265 | * |
||
266 | * @return bool |
||
267 | */ |
||
268 | 186 | public function isVFS($path) |
|
272 | } |
||
273 |