1 | <?php |
||
22 | class Filesystem extends \Symfony\Component\Filesystem\Filesystem |
||
23 | { |
||
24 | /** |
||
25 | * Build an absolute file or directory path separated by the OS specific directory separator. |
||
26 | * |
||
27 | * @param string ...$pathFragments |
||
28 | * |
||
29 | * @return string |
||
30 | */ |
||
31 | 41 | public function absolutePath($pathFragments) |
|
43 | |||
44 | /** |
||
45 | * Build a file or directory path separated by the OS specific directory separator. |
||
46 | * |
||
47 | * @param string ...$pathFragments |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | 45 | public function appendPath($pathFragments) |
|
55 | |||
56 | /** |
||
57 | * Copy a file or folder recursively. |
||
58 | * |
||
59 | * @param string $originFile The original filename |
||
60 | * @param string $targetFile The target filename |
||
61 | * @param bool $overwriteNewerFiles If true, target files newer than origin files are overwritten |
||
62 | * |
||
63 | * @throws FileNotFoundException When originFile doesn't exist |
||
64 | * @throws IOException When copy fails |
||
65 | */ |
||
66 | public function copy($originFile, $targetFile, $overwriteNewerFiles = false) |
||
95 | |||
96 | /** |
||
97 | * Create an instance of stakx's File object with relative path information. |
||
98 | * |
||
99 | * @param string $filePath |
||
100 | * |
||
101 | * @return File |
||
102 | */ |
||
103 | public function createFileObject($filePath) |
||
107 | |||
108 | /** |
||
109 | * Strip the current working directory from an absolute path. |
||
110 | * |
||
111 | * @param string $path An absolute path |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | 72 | public function getRelativePath($path) |
|
119 | |||
120 | /** |
||
121 | * Get the name of a given file without the extension. |
||
122 | * |
||
123 | * @param string $filePath A file path |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | 4 | public function getBaseName($filePath) |
|
131 | |||
132 | /** |
||
133 | * Get the name of a given file. |
||
134 | * |
||
135 | * @param string $filePath A file path |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | public function getFileName($filePath) |
||
143 | |||
144 | /** |
||
145 | * Get the parent directory of a given file. |
||
146 | * |
||
147 | * @param string $filePath A file path |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | 4 | public function getFolderPath($filePath) |
|
155 | |||
156 | /** |
||
157 | * Get the extension of a given file. |
||
158 | * |
||
159 | * @param string $filename A file path |
||
160 | * |
||
161 | * @return string The extension of the file |
||
162 | */ |
||
163 | 25 | public function getExtension($filename) |
|
167 | |||
168 | /** |
||
169 | * Check whether or not if a given path is a directory. |
||
170 | * |
||
171 | * @param string $folderPath |
||
172 | * |
||
173 | * @return bool |
||
174 | */ |
||
175 | public function isDir($folderPath) |
||
179 | |||
180 | /** |
||
181 | * Check whether or not a given path is a file. |
||
182 | * |
||
183 | * @param string $filePath |
||
184 | * |
||
185 | * @return bool |
||
186 | */ |
||
187 | public function isFile($filePath) |
||
191 | |||
192 | /** |
||
193 | * Check whether a given file path is a symlink |
||
194 | * |
||
195 | * @param string $filePath |
||
196 | * |
||
197 | * @return bool |
||
198 | */ |
||
199 | public function isSymlink($filePath) |
||
203 | |||
204 | /** |
||
205 | * Only read a file's contents if it's within the current working directory |
||
206 | * |
||
207 | * @param string $filePath |
||
208 | * |
||
209 | * @return bool|string |
||
210 | */ |
||
211 | public function safeReadFile($filePath) |
||
212 | { |
||
213 | $absPath = File::realpath($this->absolutePath($filePath)); |
||
214 | |||
215 | if (!$this->exists($absPath)) |
||
216 | { |
||
217 | throw new FileNotFoundException(sprintf( |
||
218 | "The '%s' file could not be found or is outside the website working directory", |
||
219 | $filePath |
||
220 | )); |
||
221 | } |
||
222 | |||
223 | if (strpos($absPath, Service::getWorkingDirectory()) !== 0) |
||
224 | { |
||
225 | throw new FileAccessDeniedException(sprintf( |
||
226 | "The '%s' file is outside the website working directory", |
||
227 | $filePath |
||
228 | )); |
||
229 | } |
||
230 | |||
231 | return file_get_contents($absPath); |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * Get the full path to the file without the extension. |
||
236 | * |
||
237 | * @param string $filename A file path |
||
238 | * |
||
239 | * @return string |
||
240 | */ |
||
241 | 4 | public function removeExtension($filename) |
|
248 | |||
249 | 6 | public function path($path) |
|
253 | } |
||
254 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.